1, 错误代码:m=document.getElementsByTagName("li");
m[1].style.color="";
Cannot read property 'style' of undefined
at HTMLLIElement.m.(anonymous function).onmouseover
一般这种错误都是因为‘style’前面的元素找不到,可以打印一下,发现是undefined,只要将lis[i]替换为this就可以了,this指当前元素lis[i],
2,m=document.getElementsByTagName("li");
this.style.id="a";
Cannot set property 'id' of undefined
at HTMLLIElement.m.(anonymous function).onmouseover
html dom style修改csss属性中,没有修改id这一说,若是修改id,直接
this.id="a";
Style 对象的属性:
3,Cannot set property onmouseover'of null
是页面无法加载完毕执行代码。可以把获取元素等一系列的操作放在 window.οnlοad=function(){} 中 ,或者尝试把js放在页面最底部
看错误,应该是未找到元素。
for(i=0;i<3;i++){
m[i].οnmοuseοver=function(){
this.id="over1";
childs[i].id="show";
}
m[i].οnmοuseοut=function(){
this.id="out1";
childs[i].id="hide";
}
}
}
4,当使用一个对象的未定义的属性时(return window.age ) 不会报错,并返回“undefined”,而直接使用一个未定义的变量(return age )时便会报错Uncaught ReferenceError: age is not defined。
5,<div id="div1"></div>
#div{
width:100px;
}
var aa=document.getElementById("div1");
var x=aa.style.width;
alert(x); //弹出的框什么都没有,
分析:通过js获取容器宽高度时:
当宽高都写在样式表里,通过aa.style.width拿不到宽度,而通过aa.offsetWidth才可以获取到宽度
当宽和高是写在行内中,比如style="width:120px;",这种情况通过上述2个方法都能拿到宽度。
通过js设置容器宽高度:
var aa=document.getElementById("div1");
var y=aa.offsetWidth;
aa.style.width=y+"px";
6,未解决:
<div class="div0">
<div class="div1" οnclick="moves()"></div>
<div class="div2 div8 div9">1</div>
<div class="div3 div8 div10"></div>
<div class="div4 div8 div9"></div>
<div class="div5 div8 div10"></div>
</div>
function moves(){
var x1=document.getElementsByClassName("div9");
var x2=document.getElementsByClassName("div10");
for(var i=0;i<3;i++){
x1[i].style.pixelLeft+=10;//只有ie兼容;
x2[i].style.pixelRight+=10;
}
setInterval("moves()", 10);// 这一行无法执行
}