抽奖
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <title> 抽奖活动 </title> 5 <meta name="Generator" content="EditPlus"> 6 <meta name="Author" content=""> 7 <meta name="Keywords" content=""> 8 <meta name="Description" content=""> 9 </head> 10 11 <body> 12 13 <html> 14 <head> 15 <meta http-equiv="Content-Type" content="text/html;charset=gb2312"/> 16 <meta http-equiv="Content-Language" content="zh-CN"/> 17 <title>抽奖活动</title> 18 <style type="text/css"> 19 body {padding-top:100px;font:12px "\5B8B\4F53",sans-serif;text-align:center;} 20 .result_box {margin:0 auto;width:700px;padding:100px 0;text-align:center;border:3px solid #40AA53;background:#efe;} 21 .result_box #oknum {width:700px;color:#cc0000;font-size:50pt;font-family:Verdana;text-align:center;border:none;background:#efe;} 22 .button_box {margin:50px 0 0 0;} 23 .button_box .btn {cursor:pointer;padding:0 30px;margin:0 10px;color:#555;font-family:"\5B8B\4F53",sans-serif;font-size:40px;} 24 </style> 25 </head> 26 <body> 27 <script type="text/javascript"> 28 //抽奖数据,以英文逗号分隔 29 var alldata = "张三,李四,王五,赵六,小三,小舞,白虎,金刚,狼牙,梦晓轩,紫电"; 30 var alldataarr = alldata.split(","); 31 var num = alldataarr.length-1; 32 var timer; 33 function change(){ 34 document.getElementById("oknum").value = alldataarr[GetRnd(0,num)]; 35 } 36 function start(){ 37 clearInterval(timer); 38 timer = setInterval('change()',50); //随机数据变换速度,越小变换的越快 39 } 40 function ok(){ 41 clearInterval(timer); 42 //以下代码表示获得奖的,不能再获奖了。 重置刷新页面即可。 43 alldata = alldata.replace(document.getElementById("oknum").value,"").replace(",,",","); 44 // 去掉前置,最末尾的, 45 if (alldata.substr(0,1)==",") 46 { 47 alldata = alldata.substr(1,alldata.length); 48 } 49 if (alldata.substr(alldata.length-1,1)==",") 50 { 51 alldata = alldata.substring(0,alldata.length-1); 52 } 53 alldataarr = alldata.split(","); 54 num = alldataarr.length-1; 55 } 56 function GetRnd(min,max){ 57 return parseInt(Math.random()*(max-min+1)); 58 } 59 </script> 60 <div class="result_box"><input type="text" readonly="true" id="oknum" name="oknum" value="抽奖结果" /></div> 61 <div class="button_box"><button class="btn" onclick="start()" accesskey="s">开始(<U>S</U>)</button><button class="btn" onclick="ok()" accesskey="o">停止(<U>O</U>)</button></div> 62 </body> 63 </html> 64 </body> 65 </html>
效果:
标签:box,抽奖,length,font,alldataarr,alldata From: https://www.cnblogs.com/mxx520/p/17819557.html