<div class="Default_ull" id="Default_ull" onmouseover="mouserOverDefault();">
<div style=" float:left; width:78px; height:28px; margin-top:12px; cursor:pointer; margin-left:5px; background-color:Red;"></div>
<div style=" float:left; width:70px; height:28px; margin-top:12px; cursor:pointer; margin-left:-1px; background-color:Black; "></div>
<div style=" float:left; width:70px; height:28px; margin-top:12px; cursor:pointer; margin-left:-1px;"></div>
<div style=" float:left; width:70px; height:28px; margin-top:12px; cursor:pointer; margin-left:-1px;"></div>
<div style=" float:left; width:70px; height:28px; margin-top:12px; cursor:pointer; margin-left:-1px;"></div>
<div style=" float:left; width:71px; height:28px; margin-top:12px; cursor:pointer; margin-left:-1px;"></div>
</div>
这是一小段页面的代码 当我鼠标移动到Default_ull 这个div上面的时候回触发mouserOverDefault事件
但是当我鼠标移动到内部的那些div上面的时候 还是会触发mouserOverDefault事件 我该怎么样做才能避免移动到内部div时不触发mouserOverDefault事件呢??
onmouseover = function()
{
event.returnValue=false;
event.cancelBubble=true;
return false;
}
可以取消事件的冒泡 或者在事件中检查 触发事件的对象 是否允许执行这个事件去检索一下 这个主题
var e = e || window.event;
e.stopPropagation && e.stopPropagation() || (e.cancelBubble = true);
}
function mouserOverDefault(evt) {
var e = (evt) ? evt : window.event; //判断浏览器的类型,在基于ie内核的浏览器中的使用cancelBubble
if (window.event) {
alert(1111);
e.cancelBubble = true; ;
} else {
//e.preventDefault(); //在基于firefox内核的浏览器中支持做法stopPropagation
e.stopPropagation();
}
alert();
document.getElementById("Default_ull").style.backgroundImage = "url(Images/10.png)";
}这是onmouseover触发的方法 我已经阻止冒泡事件 但是在断点调试的时候 发现内部div还是触发mouserover事件
<script type="text/javascript">
$(function() {
$(document).mouseover(function(event) {
if (event.target.id == "test1") {
alert("Test1");
}
if (event.target.id == "test2") {
alert("test2");
}
});
});
</script>
<div id="test1" style="background-color:Red;width:100px;height:50px">
<div id="test2" style="background-color:Blue;width:50px;height:25px"></div>
</div>
比如,你想进卧室,而不进你家,那怎么可能?在卧室里,你就已经在你家里了