<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>抽奖</title> <style type="text/css"> *{margin:0; padding: 0 }.class1{ background-color: #047; width: 400px; height: 50px; margin: 0 auto; padding-top: 30px; text-align: center; font-size: 34; font-weight: bold; color: #f00;}.class2{ width: 220px; height: 30px; text-align: center; font-weight: bold; margin: 0 auto;}.class2 span{display: block; float: left; width: 80px; height: 25px; line-height: 25px; background: #036; border: 1px solid #eee; border-radius: 7px; margin-right: 20px; color: #fff; text-align: center; font-size: 14px; font-family: "微软雅黑"; cursor: pointer;}</style></head><body><div id="class1" >开始抽奖啦!</div><div><span id="ksan">开 始</span><span id="stop">停 止</span></div></body></html><script type="text/javascript">var shuzu=['奖1','2','3','4','5'],t=null;window.onload=function () { var ksan=document.getElementById('ksan'); var stop=document.getElementById('stop'); ksan.onclik=kaishi; stop.onclik=jieshu; }function kaishi(){ var ksan=document.getElementById('ksan'); var title=document.getElementById('class1'); clearInterval(t); t=setInterval(function(){ var redom=Math.floor(Math.random()*shuzu.length); title.innerHtml=shuzu[redom]; },50); } function jieshu(){ clearInterval(t); }</script>
2 回答
jddod
TA贡献4条经验 获得超2个赞
问题大概是两个。。第一没有取到点击的事件。。二是,innerHtml没有把值写进去。。原因的话我觉得可能是取doc节点有问题?但是我觉得你写的没问题,试的时候就是取不到。。。所以我就改成直接取了。。本人初学者,请见谅
- 2 回答
- 0 关注
- 1199 浏览
添加回答
举报
0/150
提交
取消