用setInterval()函數執行幾次函數的最佳方法是什麼? 與是我在這裏的嘗試,即清空間隔當變量「計時器」不知道這個問題...使用setInterval()讓函數運行多次的最佳方法是什麼?
...
if (counter.hasClass("superWarn")){
var timer = setInterval(toggleCharCount(), 500);
}
...
function toggleCharCount() {
if(typeof toggleCharCount.i == 'undefined'){
toggleCharCount.i = 0;
}
toggleCharCount.i++;
$('#twCharCount').toggle();
if (toggleCharCount.i>=4){
window.clearInterval(timer);
toggleCharCount.i = 0;
}
}
THX的任何意見...
在for循環中如何? – acconrad 2011-04-07 19:22:10
你是否在另一個函數中定義了定時器? – Headshota 2011-04-07 19:24:54