<body>
<div id="div1" style="border:#0099CC 1px solid; width:100px; height:100px;"><div id="div2" style="border:#FF0000 1px solid; width:50px; height:50px;"></div></div>
<script language="javascript">  document.getElementById("div2").onmouseover=function () {
alert(event.srcElement.id);
}

document.getElementById("div2").onmouseout=function () {
alert(event.toElement.id);
}</script>
</body>

解决方案 »

  1.   

    我看错了写成src了<body> 
    <div id="div1" style="border:#0099CC 1px solid; width:100px; height:100px;"> <div id="div2" style="border:#FF0000 1px solid; width:50px; height:50px;"> </div> </div> 
    <script language="javascript"> document.getElementById("div2").onmouseover=function () { 
    alert(event.fromElement.id); 
    } document.getElementById("div2").onmouseout=function () { 
    alert(event.toElement.id); 
    } </script> 
    </body>
      

  2.   

    其实从字面意思也可以理解
    fromElement来自哪个元素
    toElement去向哪个元素
      

  3.   

    fromElement描述:检测 onmouseover 和 onmouseout 事件发生时,鼠标所离开的元素。 
    语法:event.fromElement 
    注释: 
    这是个只读属性。toElement描述:检测 onmouseover 和 onmouseout 事件发生时,鼠标所进入的元素。 参考:fromElement 
    语法:event.toElement 
    注释: 
    这是个只读属性。 
    例子:下面的代码演示了当鼠标移到按钮上时,弹出一个对话框,显示“mouse arrived” 
    <SCRIPT> 
    function testMouse(oObject) { 
        if(oObject.contains(event.toElement)) { 
            alert("mouse arrived"); 
        } 

    </SCRIPT>: 
    <BUTTON ID=oButton onmouseover="testMouse(this)">Mouse Over This.</BUTTON>