日期:2014-05-16  浏览次数:20413 次

这段javascript代码错哪了?救救我!
兄弟们,帮我看看下面这段代码错在哪?我的目的是想给表格的所有tr都加上鼠标滑过的效果。

<script   language= "javascript ">

function   method1(var   e)
{
e.style.background= "#332123 ";
}
function   method2(var   e)
{
e.style.background= "#3F21F3 ";
}

function   eventsmouse()
{
var   objsTr   =   document.all.tags( "tr ");
for(var   i=0;   i <objsTr   .length;   i++)
{
var   e   =   objsTr[i]
e.attachEvent( "onmouseover ",method1(e));
e.attachEvent( "onmouseout "   ,method2(e));

}
}
</script>

帮忙啊!


------解决方案--------------------
<table border= "1 ">
<tr>
<td> asdasd </td>
</tr>
</table>
<script language= "javascript ">

function eventsmouse()
{
var objsTr = document.getElementsByTagName( "tr ");
for(var i=0; i <objsTr .length; i++)
{
var e = objsTr[i]
e.onmouseover=function(){
this.style.backgroundColor= "red ";
}
e.onmouseout=function(){
this.style.backgroundColor= "blue ";
}
/*
e.attachEvent( "onmouseover ",new Function( "method1( "+e+ ") "));
e.attachEvent( "onmouseout " ,new Function( "method2( "+e+ ") "));
*/
}
}
eventsmouse()
</script>