`
CoArrow
  • 浏览: 13958 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

JS生成随机数

阅读更多
<script>   
  
var i=1; //counter  
  
function randValue(maxVal,no_of_time)  
  
{   
  
  i++; //counter increment   
  
  document.getElementById('random').innerHTML=''; //element made blank  
  
  //get a random no upto maxVal and round it to two decimal place  
  
  var theNumber = (Math.random()*parseInt(maxVal)).toFixed(2);   
  
  //put the number to that   
  
  document.getElementById('random').innerHTML=theNumber; //gett   
  
  if(i<=no_of_time)   
  
    setTimeout("randvalue("+maxVal+","+no_of_time+")",300);   
  
  else   
  
    i=1;  
  
}  
  
</script>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics