0
嗨我如何在div中顯示javascript結果。代碼:如何在div中顯示javascript結果
<script type='text/javascript'>
COUNTER_START = 40
function tick() {
if (document.getElementById ('counter').firstChild.data > 0) {
document.getElementById ('counter').firstChild.data = document.getElementById ('counter').firstChild.data - 1
setTimeout ('tick()', 1000)
} else {
document.getElementById ('counter').firstChild.data = 'done'
}
}
if (document.getElementById) onload = function() {
var t = document.createTextNode (COUNTER_START)
var p = document.createElement ('P')
p.appendChild (t)
p.setAttribute ('id', 'counter')
var body = document.getElementsByTagName ('BODY')[0]
var firstChild = body.getElementsByTagName ('*')[0]
body.insertBefore (p, firstChild)
tick()
}
</script>
我希望它顯示coundown計數器在這個div
<div id="counter"></div>
謝謝:d
IDS必須是唯一的 - 你不能有一個'div'和'p'使用id =計數器 – Dennis