老弟叫我帮忙他找个摇号程序,号码从001-200。最近刚看了JS高级编程的随机数这方面的知识。就自己开始动手做了一个。
代码:
var theTimer;
var iNum=0;
//var flag =true;
function checkEnter(){
if(window.event.keyCode==13){
document.getElementById("btnStop").focus();
flag=true;
if(flag){
clearTimeout(theTimer);
flag = false;
}else{
theTimer = setTimeout("checkLoad()", 8);
flag=true;
}
//document.getElementById("btnStop").click();οnkeypress="checkEnter();"
}
}
function checkLoad() {
iNum=selectFrom(1,200);
if(iNum<10){
document.getElementById("stext").innerHTML="00"+iNum;
}else if(iNum<100){
document.getElementById("stext").innerHTML="0"+iNum;
}else{
document.getElementById("stext").innerHTML=iNum;
}
theTimer = setTimeout("checkLoad()", 8);
}
function selectFrom(iFirstValue,iLastValue){
var iChoices = iLastValue-iFirstValue+1;
return Math.floor(Math.random()*iChoices+iFirstValue);
}
function stopPlay() {
clearTimeout(theTimer);
}
function resetText(){
stopPlay();
document.getElementById("hisRecord").innerText=document.getElementById("hisRecord").innerText+document.getElementById("stext").innerHTML+",";
document.getElementById("stext").innerHTML="000";
}
000
| |
历史记录: |