<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>
JS生成随机数
最新推荐文章于 2025-11-08 11:29:12 发布
本文介绍了一个使用JavaScript编写的简单网页脚本,该脚本能定时生成指定范围内的随机数并显示在页面上。通过设置最大值和次数参数,可以控制随机数的生成范围及显示次数。
1228

被折叠的 条评论
为什么被折叠?



