$(function(){
????var?timer?=?setInterval(function(){run()},400);
????var?onOff?=?true;
????$('button').click(function(){
????????if(onOff){
????????????clearInterval(timer);
????????????$(this).html('開始');
????????????onOff?=?false;
????????????//console.log(onOff)
????????}else{
????????????setInterval(function(){run()},400);
????????????$(this).html('停止');
????????????onOff?=?true;
????????????//console.log(onOff)
????????}
????});
????function?run(){console.log(Math.random())}
})<button>停止</button>想要做個點擊按鈕停止輸出隨機數,再按按鈕開始輸出隨機數,再按停止,再按開始……的功能??墒前戳说谌尉蜔o效了。
if做判斷執行到第三次就不執行了?
李下之忌心中郁
2017-01-12 09:55:18