标签:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>js随机生成</title> 5 <meta http-equiv="Content-Type" content="textml; charset=utf-8"> 6 </head> 7 <body> 8 <button id="btn">点击</button> 9 <div id="txt"></div> 10 <script type="text/javascript"> 11 var bodyBgs = []; 12 bodyBgs[0] = "1等奖"; 13 bodyBgs[1] = "2等奖"; 14 bodyBgs[2] = "3等奖"; 15 bodyBgs[3] = "4等奖"; 16 bodyBgs[4] = "5等奖"; 17 bodyBgs[5] = "6等奖"; 18 bodyBgs[6] = "7等奖"; 19 bodyBgs[7] = "8等奖"; 20 bodyBgs[8] = "9等奖"; 21 22 var btn = document.getElementById("btn"); 23 var txt = document.getElementById("txt"); 24 25 btn.onclick = function(){//点击输出随机的数字 26 var randomBgIndex = Math.round( Math.random() * 8 ); 27 txt.innerHTML = bodyBgs[randomBgIndex]; 28 } 29 </script> 30 </body> 31 </html>
标签:
原文地址:http://www.cnblogs.com/beiz/p/5069111.html