點擊按鈕後,我有一個倒數計時器。我想要做的是讓文本和計數在10的計數後消失(「在這裏開始計數」),然後將圖像從start32.png更改爲stop32.png。onclick事件並更改圖像後清除文本
var countdown;
var countdown_number;
function countdown_init() {
countdown_number = 11;
countdown_trigger();
}
function countdown_trigger() {
if(countdown_number > 0) {
countdown_number--;
document.getElementById('countdown_text').innerHTML = countdown_number;
if(countdown_number > 0) {
countdown = setTimeout('countdown_trigger()', 1000);
}
}
}
function countdown_clear() {
clearTimeout(countdown);
}
<body>
<h2>My page</h2>
<table cellpadding="10">
<tr>
<td>Click me</td>
<td><img src = "dashboard/img/start32.png"
title = "Click me"
width = "32"
height = "32"
border = "0"
onclick = "countdown_init()">
</td>
</tr>
</table>
<p>Starting counter here:</p><div id="countdown_text"> </div>
</body>
而你的問題是什麼? –