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

div嵌套div,onmouseout事件怎样判断鼠标离开最外面的div
具体代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
<script src="jquery-1.6.1.js"></script>
  <script>
function showTab1(){
alert("鼠标进入 F1");
}

function disTab1(){
alert("鼠标离开   F1");
}

function showTab2(){
alert("鼠标进入 F2");
}

function disTab2(){
alert("鼠标离开   F2");
}

function showTab3(){
alert("鼠标进入 F3");
}

function disTab3(){
alert("鼠标离开   F3");
}

  </script>
 </head>
 <body>
  <br/>
  <div id="f1" style="width:400px; height:400px; background:green;" onmouseover="showTab1()" onmouseout="disTab1()">
 <div id="f2" style="width:200px; height:200px; background:blue;" onmouseover="showTab2()" onmouseout="disTab2()">
 <div id="f3" style="width:100px; height:100px; background:red;" onmouseover="showTab3()" onmouseout="disTab3()">
 </div>
</div>
  </div>
<br/>
 
 </body>
</html>




RT:怎样判断鼠标离开了最外面的div f1

------解决方案--------------------
获取最外层的div的所有子元素(包括<a/>、<div/>、<p/>等等)

监听document的onmouseover事件

判断触发事件的元素是否div或div的子元素
------解决方案--------------------

var getAllChildNodes = function(obj){//得到某元素的子元素(包括子元素的子元素)
var nodes = obj.childNodes;
var arr = [];