为什么当我执行一个alert
值(见下文)时它会返回null
?何时存在具有该 ID 的元素?
// make reference to divs
var countdown_timer = document.getElementById("countdown_timer");
var countdown_image = document.getElementById("countdown_image");
// For element manipulation
if (type == 'image') {
var element = countdown_image;
} else if (type == 'timer') {
var element = countdown_timer;
}
alert(countdown_timer);
div如下..
<div class="timer" id="countdown_timer"></div>