我得到這些數字工作,但字母「T」已被替換,以便它不會顯示。你們有沒有關於如何讓它工作的想法。非常感謝你。jquery數字計數器結合字符串
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
return val;
}
$('.number').each(function() {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 8000,
easing: 'swing',
step: function (now) {
$(this).text(commaSeparateNumber(Math.ceil(now)));
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-4">
<div class="count"><div class="number">30</div></div>
<div class="text">text 1</div>
</div>
<div class="col-md-4">
<div class="count"><div class="number">3000</div></div>
<div class="text">text 2</div>
</div>
<div class="col-md-4">
<div class="count"><div class="number">700<span>T</span></div></div>
<div class="text">text 3</div>
你嘗試過移動與div.number的「T」之外的跨度? – happymacarts
我已經嘗試過,但我想跨度內div.number – Tony
目前還不清楚你在問什麼。這是其他問題的延續嗎? –