jquery - 使用 jQuery 将“1”增加到格式化数字
问题描述
我在我的 HTML 中显示了一个用 PHP 格式化的数字字段。
$totalShares = get_field('share_count');
$totalFormat = number_format( $totalShares, 0, '.', ',' );
echo 'Shared: <span class="totalShares">'.$totalFormat.'</span> times';
使用 jQuery 和 Ajax,我通过单击按钮添加 1,但它会将 HTML 中的例如 8,500 (8500) 转换为 9。如果我刷新,我有 8,501。
jQuery(function($) {
$('.social-icon').on('click', function() {
$.ajax({
url: bloginfo.site_url + '/wp-json/functions/shares/' + bloginfo.post_id.ID,
type: 'post',
success: function() {
console.log('works!');
},
error: function() {
console.log('failed!');
}
});
// Change the like number in the HTML to add 1
var updated_shares = parseInt($('.totalShares').html()) + 1;
$('.totalShares').html(updated_shares);
});
});
如何纠正这部分var updated_likes = parseInt($('.share_count').html()) + 1;
?
谢谢您的帮助。
解决方案
推荐阅读
- java - 如何使用 Java Spring 读取 SOAP API 请求标头
- log4j - log4j 使用 html 布局创建空文件
- python - 如何快速将 python docxTemplate 保存为 pdf
- android - Android改造OAuth twitch api我每秒获得不同的访问令牌
- wordpress - 我想从 WooCommerce 管理员编辑页面编辑结帐字段
- javascript - nodejs中的倒数计时器
- javascript - 如何在 Angular 11 材料中的 Stepper 中获取 formControlName 值形式?
- amazon-web-services - 将 MySQL 行从一个表迁移和转换到另一个表
- swift - 进程未终止 macOS 应用程序/终止正在运行的进程
- python - 如何将日期转换为数字?