JS问题/jquery问题如何让DIV里的元素不触发mouseover事件?

发布时间:2019-08-06 11:54:48

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>测试</title>
<style type="text/css">.test{width:500px; height:100px; background:red; margin-top:270px; }
</style>
<script type=text/javascript src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">$(function(){ $('.test').mouseover(function(){
alert(1);
});
});
</script>
</head><body>
<div class="test">
<a href="#">xxxx</a>
</div>
</body>
</html> //当鼠标移动到test的时候输出1,当鼠标移动到test里的a的时候又触发了一次mouseover,应该如何让它不触发?

推荐回答

$(".test").mouseover(function(){ alert("aaa"); }).find("*").mouseover(function(){return false;}); });要阻止事件冒泡,比较傻的方法...网上的event.stopPropagation()不好用,还有兼容性问题...干脆继续用jq重写元素事件,或者你用hover方法,好像没有冒泡。
以上问题属网友观点,不代表本站立场,仅供参考!