某處在我的代碼,我調用這個函數:如何讓一個函數`clearInterval`本身?
function call_bid_button(id)
{
bid_button(id);
var refreshIntervalId = setInterval(function(){bid_button(id)},1000);
}
正如你可以看到通話功能bid_button()
並設置interval
它。
我想bid_button()
自己激活clearInterval()
。下面是bid_button()
:
function bid_button(id)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200 && xmlhttp.responseText=='')
{
document.getElementById("bid_button").innerHTML=xmlhttp.responseText;
clearInterval(refreshIntervalId);
}
}
xmlhttp.open("GET","the_bid_button.php?id="+id,true);
xmlhttp.send();
return false;
}
正如你所看到的,我試圖調用clearInterval()
從另一個功能。顯然,這是行不通的。儘管如此,正確的方法是什麼?
由於
我想過,但我認爲這是行不通的。現在我明白了它爲什麼起作用。謝謝 –