事件冒泡解决方案

来源:互联网 发布:za的护肤品怎么样知乎 编辑:程序博客网 时间:2024/05/16 13:59

冒泡解决方案

div  里面绑定div  2个DIV都绑定了 click事件,怎么点里面的div不会执行到外面DIV的事件,冒泡!这个案例 比较简单,仅供大家学习  案例下载地址



<!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=utf-8" /><title>无标题文档</title></head><body><style>.box{ border:1px #ddd solid; width:400px; height:400px; margin:0 auto;}.search{ width:200px; height:200px; margin:100px; border:1px #000 solid}</style><div class="box"><div class="search"></div></div><script type="text/javascript" src="js/jquery-2.0.3.min.js"></script><script>$(function(){$(".search").click(function(event){event.stopPropagation();alert("1")})$(".box").click(function(event){alert("2")})})</script></body></html>


0 0