为了账号安全,请及时绑定邮箱和手机立即绑定

求各位大哥帮忙查查错误,我实在找不出了

求各位大哥帮忙查查错误,我实在找不出了

Sprash 2016-03-21 18:39:53
<html><head><meta charset="utf-8"> <style type="text/css"> .wrap{margin: 0 auto;width: 400px;height: 240px; } .price{  width: 300px;height: 40px;text-align: center;line-height: 40px;margin: 0 auto;margin-bottom: 20px; } .begin{  float: left;  background-color:blue;  color: white;  width: 90px;  text-align: center;  height: 35px;  line-height: 35px;  margin:0 20 0 80;  } .stop{  float: left;  background-color:blue;  color: white;  width: 90px;  text-align: center;  height: 35px;  line-height: 35px; margin:0 20 0 80;  } </style></head><body> <div class="wrap"> <div class="price" id="price">抽奖开始</div> <button class="begin" id="begin">开始</button> <button class="stop" id="stop">停止</button></div><script type="text/javascript">var jp=['Phone5','Ipad','三星笔记本','佳能相机','惠普打印机','谢谢参与','50元充值卡','1000元超市购物券'];var begin=document.getElementById("begin");var stop=document.getElementById("stop");var price=document.getElementById("price");var timmer=null;begin.onclick=a1;stop.onclick=stopFun;var i=0;function a1(){ var timmer=setInterval(a11,100); begin.style.backgroundColor="grey";  begin.style.color="white";  begin.onclick=null;}function a11() {  price.innerHTML=jp[i];  i++;  if(i==jp.length){  i=0;  }}function stopFun(){ clearInterval(timmer); }</script></body></html>这个是一个抽奖系统的代码,开始点开始便开始抽奖,点stop就停止,但是现在问题是,我点stop没用。求解问题出在哪。谢谢各位
查看完整描述

1 回答

已采纳
?
woshiajuana

TA贡献211条经验 获得超152个赞

你前面已经声明了var timmer=null; 这个timmer变量

你后面在函数a1里给它赋值的时候又用(var timmer=setInterval(a11,100);)var声明了一次,相当于两个timmer变量,你最后stopFun函数里的timmer不是同一个变量,也就造成了停止不了

所以把函数a1里面的var timmer=setInterval(a11,100);改成timmer=setInterval(a11,100)就行了


查看完整回答
反对 回复 2016-03-22
  • 1 回答
  • 1 关注
  • 1335 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信