亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求各位大哥幫忙查查錯誤,我實在找不出了

求各位大哥幫忙查查錯誤,我實在找不出了

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 關注
  • 1446 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號