setAttribute("onmouseover",.....的问题
//代码如下
<div id= "test " style= "width:400px; ">
</div>
<script language= "javascript " type= "text/javascript ">
var e1 = document.getElementById( "test ");
var newDiv = document.createElement( "div ");
var textNode = document.createTextNode( "aaaaaaaaaaa ")
newDiv.setAttribute( "onmouseover ", "this.style.color= 'red ' ");
newDiv.setAttribute( "onmouseout ", "this.style.color= 'green ' ");
newDiv.appendChild(textNode);
e1.appendChild(newDiv);
</script>
//----------------------------------------------
//问题:当鼠标经过时没有反应
//而如下代码能正常运行
<div onmouseover= "this.style.color= 'red ' " onmouseout= "this.style.color= 'green ' ">
fsdfdsfsd
ssdfsdfsd
</div>
------解决方案--------------------newDiv.onmouseover=new Function( "this.style.color= 'red ' ");
newDiv.onmouseout=new Function( "this.style.color= 'red ' ");
这样写行不?