Javascript 如何让js函数显示随机数而不是计数

Javascript 如何让js函数显示随机数而不是计数,javascript,Javascript,我如何改变以下函数,使其显示随机数而不是计数到最终数 $('.counter').each(function() { var $this = $(this), countTo = $this.attr('data-count'); $({ countNum: $this.text() }).animate({ countNum: countTo }, { duration: 1000, easing: 'linear', step:

我如何改变以下函数,使其显示随机数而不是计数到最终数

$('.counter').each(function() {
  var $this = $(this),
    countTo = $this.attr('data-count');
  $({
    countNum: $this.text()
  }).animate({
    countNum: countTo
  }, {
    duration: 1000,
    easing: 'linear',
    step: function() {
      $this.text(Math.floor(this.countNum));
    },
    complete: function() {
      $this.text(this.countNum);
      var element = document.getElementById('result');
      element.style.opacity = "1";
      element.style.filter = 'alpha(opacity=1)'; // IE fallback

      var button = document.getElementById('return');
      button.style.opacity = "1";
      button.style.filter = 'alpha(opacity=1)'; // IE fallback

    }
  });
});
提前感谢。

这是:

step: function() {
    $this.text(Math.floor(this.countNum));
},
应该是:

step: function() {
    var min = 5; // change min if you want to
    var max = 200; // change max if you want to
    $this.text(Math.floor(Math.random() * (max - min) + min)); // use Math.random to generate the random numbers
},

非常感谢,这正是我想要的!:)不客气!你的代码需要整理一下@Patrick没关系,我只是觉得
动画的前两个参数不再是必需的。啊,好吧!无论如何谢谢你的帮助,真的很感激!