$(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>想要做個(gè)點(diǎn)擊按鈕停止輸出隨機(jī)數(shù),再按按鈕開始輸出隨機(jī)數(shù),再按停止,再按開始……的功能??墒前戳说谌尉蜔o(wú)效了。
if做判斷執(zhí)行到第三次就不執(zhí)行了?
李下之忌心中郁
2017-01-12 09:55:18