關(guān)于判斷回車是結(jié)束還是開始的問題!
老師在視頻里面設(shè)了個(gè)flag參數(shù)來判斷是第幾次按, 如果不用這個(gè),換成判斷此時(shí)定時(shí)器是不是在運(yùn)行,或者是開始按鈕是不是灰色之類的判斷是不是會(huì)更簡(jiǎn)單啊?
老師在視頻里面設(shè)了個(gè)flag參數(shù)來判斷是第幾次按, 如果不用這個(gè),換成判斷此時(shí)定時(shí)器是不是在運(yùn)行,或者是開始按鈕是不是灰色之類的判斷是不是會(huì)更簡(jiǎn)單啊?
2016-04-02
舉報(bào)
2016-04-23
考慮程序的健壯性應(yīng)該不能設(shè)置flag,要根據(jù)定時(shí)器是否執(zhí)行更好,因?yàn)榭赡苡脩粼谟檬褂面I盤事件開始,按鈕點(diǎn)擊事件結(jié)束時(shí),設(shè)置flag就沒有用了
2016-04-27
var?data=['Phone5','Ipad','三星筆記本','佳能相機(jī)','惠普打印機(jī)','謝謝參與','50元充值卡','1000元超市購物券'], ????timer?=?null, ????isRun?=?false; window.onload?=?function(){ ????var?oTitle?=?document.getElementById('title'), ????????btn_play?=?document.getElementById('play'), ????????btn_stop?=?document.getElementById('stop'); ????btn_play.onclick?=?playFun; ????btn_stop.onclick?=?stopFun; ????//開始按鈕點(diǎn)擊事件 ????function?playFun(){ ????????if(!isRun){ ????????????timer?=?window.setInterval(function(){ ????????????var?random?=?Math.floor(Math.random()*data.length); ????????????oTitle.innerHTML?=?data[random]; ????????????isRun?=?true; ????????????btn_play.style.background="#ccc"; ????????????btn_stop.style.background=''; ??????????},100); ????????} ???????? ????} ????//停止按鈕點(diǎn)擊事件 ????function?stopFun(){ ????????if(isRun){ ????????????window.clearInterval(timer); ????????????btn_play.style.background=''; ????????????btn_stop.style.background='#ccc'; ????????????isRun=false; ????????} ????????alert("你抽中了"+oTitle.innerHTML+"!?恭喜!"); ????} ????//按鍵事件 ????document.onkeyup?=?function(event){ ????????event?=event||window.event; ????????//如果符合設(shè)定的按鍵 ????????if(event.keyCode==13||event.keyCode==32){ ????????????if?(isRun)?{ ????????????????stopFun(); ????????????}else{ ????????????????playFun(); ????????????} ????????} ????} }這樣么?
2016-04-03
都可以....