代码如下: <html> <title>模拟抽奖(Dicky.CnBlogs.Com)</title> <head> <meta name="keywords" content="Dicky,AppleBBS,Dicky.CnBlogs.Com"> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> </head> <body> <SCRIPT LANGUAGE="JavaScript"> var alldata = "青苹果论坛,Dicky.8800.Org/BBS1,Dicky.CnBlogs.Com,AppleBBS,Dicky,大雨点,51windows,blueidea,csdn,google,baidu,msn,qq,cctv,microsoft,adobe" //抽奖的姓名,以,为分隔 var alldataarr = alldata.split(",") var num = alldataarr.length-1 var timer function change(){ document.getElementById("oknum").value = alldataarr[GetRnd(0,num)]; } function start(){ clearInterval(timer); timer = setInterval('change()',50); //50(毫秒)为变换间隔,越小变换的越快 } function ok(){ clearInterval(timer); } function GetRnd(min,max){ return parseInt(Math.random()*(max-min+1)); } </SCRIPT> 模拟抽奖:<input type="text" id="oknum" name="oknum" value=""> <button onclick="start()" accesskey="s">开始(<U>S</U>)</button> <button onclick="ok()" accesskey="o">停止(<U>O</U>)</button> </body> </html> [Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码] 来源:https://www.cnblogs.com/Dicky/archive/2005/10/21/258819.html 标签 js代码 js