如何在Javascript中为我的计数加载器添加百分号

时间:2016-03-06 15:32:34

标签: javascript jquery

我有一个问题是将百分号添加到我的计数器,这是一个加载器,我试图在数字旁边添加百分号,我想不出办法做到这一点,我尝试使用+'%'代码Javascript但不起作用......

有人可以帮忙吗?

$('.count').each(function() {
  $(this).prop('Counter', 0).animate({
    Counter: $(this).text()
  }, {
    duration: 1500,
    easing: 'swing',
    step: function(now) {
      $(this).text(Math.ceil(now));
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="count">100</p>

2 个答案:

答案 0 :(得分:3)

使用:

$(this).text(Math.ceil(now) + "%");

答案 1 :(得分:2)

你可以在css中使用伪后的

p:after{
  content:"%"
}
<p>100</p>

相关问题