我希望alertMe函數僅在單擊該按鈕時被調用,但會被調用(setInterval被調用哪個調用該函數)就像頁面加載一樣。但是如果我把pageLoad函數帶走,那麼startButton就是null,我不能用它做任何事情。提前感謝,夥計們!setInterval()如何處理button.onclick
/when user clicks start, start the animation
window.onload = pageLoad;
function pageLoad() {
var startButton = document.getElementById("start");
startButton.onclick = setInterval(alertMe,200);
}
function alertMe() {
alert("hi");
}
按鈕被點擊。 – 2013-03-25 02:13:19
是不是說「onlick」函數表示按鈕已被點擊? – 2013-03-25 02:15:22
正確,但它被分配給您的語句的返回值,而不是它可以執行的函數。 – ahren 2013-03-25 02:23:15