我有一个特定的数字,我使用计数器 jquery 函数,以便该数字在特定时间段内从 0 到该数字进行动画处理。现在,问题是当我将 ,(逗号)或 .(点)添加到数字中作为千位分隔符时,它不起作用。如何使脚本与 ,(逗号)和 .(点)分隔符一起工作,并使用 ,(逗号)和 .(点)返回结果?
html
<div class='number_container'>
<span class='count'>317249</span>
</div>
CSS
.number_container {
background: red;
width: 100px;
text-align: center;
padding: 38px 0;
border-radius: 50px;
color: white;
margin: 0 auto;
}
.count {
font: 20px arial;
}
Js
$(document).ready(function() {
$('.count').each(function() {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 3500,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now));
}
});
});
});
Jsfiddle 预览
https://jsfiddle.net/y6zdmaeq/
我希望数字317249显示为317,249或317.249并从0开始计数。谢谢
最佳答案
结合this answer和您的代码,只需在 .text()
关于javascript - 如何在由 .(点)或 ,(逗号)作为千位分隔符分隔的数字上使用 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33559587/