0
我是JavaScript新用戶。在redPic.onclick我想重置超時,然後再次啓動它。我不想使用jQuery。可能嗎?setTimeout我無法再次啓動該功能
let redPic = document.createElement('img');
redPic.src = "610f326c4fa418d6221909abdb8c67a824837df3f7397b840d9a3376.png";
redPic.width = "90";
function putPicOnRandomPlace() {
let showRedPic = document.getElementById(Math.floor(Math.random() * 9) + 1);
showRedPic.appendChild(redPic);
}
putPicOnRandomPlace();
let timeOut = setTimeout(function() {
alert('game over!');
}, 3000)
redPic.onclick = function() {
putPicOnRandomPlace();
clearTimeout(timeOut);
timeOut = setTimeout(function() {
alert('game over!');
}, 3000)
}
您鏈接的圖像似乎不存在。 showRedPic看起來像它抓住了一些我們需要看到的幫助你的html。 –
看起來像一個*** whack-a-mole ***遊戲 –