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

onmouseover直接附加不起作用?
<span   id= "SP ">
<input   value= "222 "   id= "btn1 ">

<script   language= "javascript ">
document.all.btn1.onmouseover= "alert( 'aa ') ";
document.all.btn1.onclick= "alert( 'aa ') ";
</script>
</span>

此时btn的onmouseover无效,但如果将 <span> 的内容重新赋值则生效。
有什么办法解决?不用attachEvent方法。

------解决方案--------------------
document.all.btn1.onmouseover=function (){ "alert( 'aa ') ";}
------解决方案--------------------
onmouseover指定处理函数,只在事件触发时来运行函数。
------解决方案--------------------
<span id= "SP ">
<input value= "222 " id= "btn1 " onmouseover= "alert( 'aa ') " onclick= "alert( 'aa ') ">
</span>
------解决方案--------------------
document.all.btn1.onmouseover=function () {alert( 'aa ');};
document.all.btn1.onclick= function () {alert( 'aa ');};