roundNum
에 대해 쉼표를 구현했습니다.이 중 쉼표는 내가 이동하는 합계를 표시합니다.숫자에 쉼표 추가 문제
$.fn.digits = function(){
return this.each(function(){
$(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
});
};
$('.total').text(roundNum).digits();
그러나 나는 실제 카운터와 같은 것을 할 수 없습니다.
$('.total').text(roundNum)
문자열을 반환 :
$.fn.countTo = function(options) {
// merge the default plugin settings with the custom options
options = $.extend({}, $.fn.countTo.defaults, options || {});
// how many times to update the value, and how much to increment the value on each update
var loops = Math.ceil(options.speed/options.refreshInterval),
increment = (options.to - options.from)/loops;
return $(this).each(function() {
var _this = this,
loopCount = 0,
value = options.from,
interval = setInterval(updateTimer, options.refreshInterval);
function updateTimer() {
value += increment;
loopCount++;
$(_this).html(value.toFixed(options.decimals));
if (typeof(options.onUpdate) == 'function') {
options.onUpdate.call(_this, value);
}
if (loopCount >= loops) {
clearInterval(interval);
value = options.to;
if (typeof(options.onComplete) == 'function') {
options.onComplete.call(_this, value);
}
}
}
});
};
$.fn.countTo.defaults = {
from: 0, // the number the element should start at
to: 100, // the number the element should end at
speed: 1000, // how long it should take to count between the target numbers
refreshInterval: 100, // how often the element should be updated
decimals: 0, // the number of decimal places to show
onUpdate: null, // callback method for every time the element is updated,
onComplete: null, // callback method for when the element finishes updating
};
$('.timer').countTo({
from: 0,
to: roundNum,
speed: speed,
refreshInterval: 600,
onComplete: function() {
console.debug(this);
}
});
: 아마 무엇에 가장 적합한 단지 수신 번호 나 문자열을 받아들이고 그냥이 작업을 수행 할 수 있도록 쉼표 얘기들이었다 문자열을 반환하는 일반 기능으로
digits()
코드를 확인하는 것입니다 이 스레드 : http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript –@SteveKline 질문을 읽어 주신다면, 이미 기능을 가지고 있지만 다른 문제를 구현하는 데 문제가 있습니다. –
그 부분을 간과해서 죄송합니다. 사과. –