tagname提示为空
Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
2020-03-24
提示为空,说明你没有获取到正确的DOM元素,用console.log检查下。
window.onload=function(){
var menu = document.getElementById('menu');
var item = menu.getElementsByTagName('div');
for(var i = 0; i < item.length; i++) {
item[i].onclick = function() {
for(var i = 0; i < item.length; i++) {
item[i].children[1].style.display = 'none';
}
this.children[1].style.display = 'block';
}
}
举报