setInterval傳參數實踐

方法採用博客 https://blog.csdn.net/iteye_7932/article/details/82520685javascript

方法1:測試後,可用,能夠重複調用方法,而且timer1爲23,所以能夠中止定時器。java

var timer1;
var jfkdjfk;
StartInterval.onclick=function(){
console.log('startInterval->');
jfkdjfk=4;
timer1=window.setInterval('hello(jfkdjfk)',3000,jfkdjfk);
console.log(timer1);
}
StopInterval.onclick=function(){
    console.log('stopInterval->');
    console.log(timer1);
    window.clearInterval(timer1); 
}
function hello(num)
{ console.log('hello'+num); }

方法3:(重寫SetInterval方法)測試

測試後,發現只能實現重複調用,可是中止定時器時,timer1爲undefined,所以不能中止定時器。.net

相關文章
相關標籤/搜索