提示錯誤getElementsByTagName
一直提示 Uncaught TypeError: Cannot read property 'getElementsByTagName' of null 為什么啊
代碼如下
function $(id) {
return typeof id === 'string' ? document.getElementById(id) : id;
};
window.onload = function() {
//獲取鼠標(biāo)滑過或點擊的標(biāo)簽和要切換內(nèi)容的元素
var titles = $("notice-title").getElementsByTagName("li");
var divs = $("notice-content").getElementsByTagName("div");
if(titles.length != divs.length) return;
}
2019-06-04
我也是
2019-05-27
2018-12-15
并沒有錯啊,我在你定義變量后面添加alert(titles.ength),可以出現(xiàn)警示框并顯示5