<div onMouseOver="alert('a')" style=" height:400px; width:500px; padding:20px; border:1px solid #000000">
<div id='t1' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">1 </div>
<div id='t2' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">2 </div>
<div id='t2' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">3</div>
<div id='t2' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">4</div>
</div>
阻止事件冒泡cancelBubble = true
<div id='t1' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">1 </div>
<div id='t2' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">2 </div>
<div id='t2' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">3</div>
<div id='t2' onMouseOver="event.cancelBubble = true " style=" height:50px; width:200px; padding:20px; border:1px solid #000000">4</div>
</div>
阻止事件冒泡cancelBubble = true
function show(c)
{
alert(c.id);
}
</script>
<div id="total" onmouseover="show(this)">
<div id='t1'>1 </div>
<div id='t2'>2 </div>
<div id='t3' onmouseover="show(this)">3 </div>
<div id='t4' onmouseover="show(this)">4 </div>
</div>
<div>
<div id='t1'>1 </div>
<div id='t2'>2 </div>
<div id='t3'>3 </div>
<div id='t4'>4 </div>
<div onmourseover="alert('111')"></div>
</div>
<div id='t1' onmouseover="checkandshow(this.id)">1 </div>
<div id='t2' onmouseover="checkandshow(this.id)">2 </div>
<div id='t3' onmouseover="checkandshow(this.id)">3 </div>
<div id='t4' onmouseover="checkandshow(this.id)">4 </div>
</div>
<script language="javascript">
function checkandshow(x)
{
if(this.id!="t0")
{
alert("1");
}
else
{
alert("2");
}
}
</script>
好像不行
不过.我们在程序中一般都是可以控制它的,可以通过判断来实现我们想要的效果.
function checkEvent()
{
if(window.event)
{
var obj = event.srcElement;
var objId = obj.id;
switch(objId)
{
case "tt":
...
break;
case "t1":
//不触发相应的事件
break;
case "t2":
...
}
}
}<div onmourseover="checkEvent">
<div id='t1'>1 </div>
<div id='t2'>2 </div>
<div id='t3'>3 </div>
<div id='t4'>4 </div>
</div>
但是反过来,从内层的div到外层来,又触发了一次!( 既然内层的div包含在外层的div内, 按理说是不再触发的!)等待高手解答, 苦闷ing~~~