HTML: `
<li><div class="zb_font"><font color="#FF0000"> * </font>first</div></li>
<li><div class="zb_font"><font color="#FF0000"> * </font>second</div></li>
<li><div class="zb_font"><font color="#FF0000"> * </font>third</div></li>
<li><div class="zb_font"><font color="#FF0000"> * </font>last</div></li>
`
的javascript:
function myFunc(){
var change = document.getElementsByClassName('zb_font')[3];
change.innerHTML = '4';
}
我确信该函数已被调用,但我仍然得到“TypeError:change is undefined”。
答案 0 :(得分:0)
确保在加载DOM后运行javascript。例如:
document.onload = function() {
// your function.
};