大布and科比
2015-08-23 15:48
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>抽奖系统</title>
<style type="text/css">
#cj{width:200px;margin:0 auto;text-align:center;}
span{color:red;font-size:30px;}
input{margin:20px 0;}
</style>
<script type="text/javascript">
window.onload=function(){
var sz=new Array('苹果笔记本','ipad','100元充值卡','平板电脑','小米手机','500元现金','耳机');
var ks=document.getElementById("ks");
var js=document.getElementById("js");
var guen=document.getElementsByTagName("span");
var c=0;
//点击按钮抽奖
ks.onclick=kaishi;
js.onclick=jieshu;
//按enter键抽奖
document.onkeyup=function(event){
event=event||window.event;
if(event.keyCode==13){
if(c==0){
kaishi();
c=1;
}else{
jieshu();
c=0;
}
}
}
}
function kaishi(){
var guen=document.getElementsByTagName("span");
var sz=new Array('苹果笔记本','ipad','100元充值卡','平板电脑','小米手机','500元现金','耳机');
clearInterval(timer);
timer=setInterval(function(){
var i=Math.floor(Math.random()*sz.length);
guen[0].innerHTML=sz[i];
},100);
}
function jieshu(){
clearInterval(timer);
}
</script>
</head>
<body>
<div id="cj">
<span>准备抽奖了</span><br/>
<input id="ks" type="button" value="开始抽奖">
<input id="js" type="button" value="结束抽奖">
</div>
</body>
</html>
厉害厉害
DOM事件探秘
99544 学习 · 1197 问题
相似问题