例4,JS随机数显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>js随机数显示-www.jb200.com</title> <script type="text/javascript"> var seconds = 30; window.onload = function () { setInterval("reMainTime()", 100); } function RndNum(n){ var rnd=""; for(var i=0;i<n;i++) rnd+=Math.floor(Math.random()*10); return rnd; } function reMainTime() { if (seconds > 0) { var divMsg = document.getElementById("msgDiv"); divMsg.innerHTML = RndNum(1);//丢入随机数 seconds--; } else { return; } } </script> </head> <body> <div id="msgDiv"></div> </body> </html>
例5,Js 随机数产生6位数字
<script type="text/javascript"> /** * js随机数 * www.jb200.com */ function MathRand() { var Num=""; for(var i=0;i<6;i++) { Num+=Math.floor(Math.random()*10); } document.getElementById("Lb_Random").innerText=Num; document.getElementById("Lb_Random").innerHTML=Num; } </script>