為什么功能可以實(shí)現(xiàn),在調(diào)試時(shí)卻顯示Uncaught TypeError: Cannot set property 'onmouseover' of undefined
?function Highlight(){
? ??? ?? var tbody=document.getElementById("table").lastChild;
? ??? ?? var trs=tbody.getElementsByTagName("tr");
? ??? ?? for(var i=0;i<=trs.length;i++){
? ??? ? ??? ?trs[i].onmouseover=function(){
? ??? ? ??? ??? ?this.style.backgroundColor="#f2f2f2";
? ??? ? ??? ?}
? ??? ???? trs[i].onmouseout=function(){
? ??? ???????? this.style.backgroundColor="#fff";
? ??? ???? }
? ??? ?? }
? ??? ?}
2016-03-07
for(var i=0;i<=trs.length;i++)改為for(var i=1;i<=trs.length;i++);
i應(yīng)該從1開始,trs[0]指的是空白節(jié)點(diǎn),也就是tbody標(biāo)簽后面的回車。