日期:2014-05-16 浏览次数:20421 次
<html> <head> <title></title> <style type="text/css"> *{font-size:12px;color:#666666;} ul{list-style-type:none;margin:0;padding:0;} #log{border:1px solid #e9e9e9;height:240px;width:120px;position:absolute;right:0;top:0;overflow:scroll;} </style> </head> <body> <div id="log"></div> <ul> <li id="test"><a href="#">test</a> <ul> <li>3424234</li> <li>3424234</li> <li>3424234</li> <li>3424234</li> <li>3424234</li> <li>3424234</li> </ul> </li> </ul> <script type="text/javascript"> document.getElementById("test").onmouseover=function(event){ var evt=window.event||event; document.getElementById("log").innerHTML+=evt.type+"<br />"; } </script> </body> </html>
<html> <head> <title></title> <style type="text/css"> *{font-size:12px;color:#666666;} ul{list-style-type:none;margin:0;padding:0;} #log{border:1px solid #e9e9e9;height:240px;width:120px;position:absolute;right:0;top:0;overflow:scroll;} </style> </head> <body> <div id="log"></div> <ul> <li id="test"><a href="#">test</a> <ul> <li>3424234</li> <li>3424234</li> <li>3424234</li> <li>3424234</li> <li>3424234</li> <li>3424234</li> </ul> </li> </ul> <script type="text/javascript"> document.getElementById("test").onmouseover=function(event){ var evt=window.event||event; var s = evt.fromElement || evt.relatedTarget; if( document.all ){ if( !(s == this || this.contains(s)) ){ document.getElementById("log").innerHTML+=evt.type+"<br />"; } }else{ var res= this.compareDocumentPosition(s) ; if( !(s == this || res == 20 || res == 0 ) ){ document.getElementById("log").innerHTML+=evt.type+"<br />"; } } } </script> </body> </html>
------解决方案--------------------
<script type="text/javascript"> document.getElementById("test").onmouseover=function(event){ var evt=window.event||event; // 来源dom evt.relateTarget = evt.fromElement || evt.relateTarget; var fromEl = evt.relateTarget; // 如果是从BODY滑入的 if(fromEl.tagName == "BODY") { document.getElementById("log").innerHTML+=evt.type+"<br />"; } } </script>