向上计数的数字添加百分比jquery

Add percentage to number counting up jquery

本文关键字:添加 百分比 jquery 数字      更新时间:2023-09-26

我想在从0到100的每个数字后面加一个%,并将其用作加载器。我试着添加

$(".timer").append("%");

但这只会把它加到最后一个数字上。我们总是乐于助人。

http://jsfiddle.net/YWn9t/

谢谢!

您还可以使用css after伪类:

.timer:after
{
    content:'%';
}

至于javascript代码,在更新值时需要将其附加到updateTimer函数中:

function updateTimer() {
    value += increment;
    loopCount++;
    $(_this).html(value.toFixed(options.decimals));
    $(".timer").append('%');
    ...
}

当然,您可以添加%作为.timer元素的同级span元素。

您可以在HTML中硬编码%,然后将其与.timer元素内联显示。

当您在updateTimer函数中设置HTML内容时,可以附加%

$(_this).html(value.toFixed(options.decimals) + '%');

更新的Fiddle

您可以使用每个的方法

类似的东西

$(".timer").each(function(){
    $(this).append("%");
});