<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>游戏卡</title>
<style type="text/css" >
#p{background-color:#99CC99; width:400px; height:400px;border:5px;}</style>
<script type="text/javascript">
function a (){
var b=document.getElementById(p);
var c=Math.random()*100;
document.write(Math.round(c));}
widow.onload=a();
</script>
</head>
<body><table id="p"><tr><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
</table>
</body>
</html>
要在表格随机生成数字,怎么实现
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>游戏卡</title> <script type="text/javascript"> function a (){ var sty = "<style type=" + "text/css"+" >#p{background-color:#99CC99; width:400px; height:400px;border:5px;}</style>"; document.write(sty); document.write("<table border = 1 id =" + "p" +">"); for (var i=0;i<5;i++){ document.write("<tr>"); for (var j =0;j<5;j++){ document.write("<td>"); document.write(Math.round(Math.random()*100)); document.write("</td>"); } document.write("</tr>"); } document.write("</table>"); } </script> </head> <body onload="a()"> </body> </html>
Math.random 吧,有几个表格循环random几次就可以了
用Math.random()方法可返回介于 0 ~ 1(大于或等于 0 但小于 1 )之间的一个随机数。用Math.round(x)可以四舍五入。