- <!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>
- <script type="text/javascript" src="http://shawphy.com/common/jquery.js"></script>
- </head>
- <body style="background:black;width:100%;height:100%;margin:0;padding:0">
- <div id="showdiv" style="background:white">click here to show a div.</div>
- <div id="test" style="background:white;display:none;width:150px;height:150px;">
- <ul id="">
- <li>list 1</li>
- <li>list 2</li>
- </ul>
- <a href="#">close</a>
- </div>
- </body>
- <script type="text/javascript">
- <!--
- $(function() {
- $("#showdiv").click(function(e) {
- if ($("#test").is(":hidden")) {
- $("#test").fadeIn();
- e.stopPropagation();
- }
- });
- $("#test").click(function(e) {
- e.stopPropagation();
- });
- $(document).click(function() {
- $("#test").fadeOut();
- });
- $("#test a").click(function() {
- $("#test").fadeOut();
- });
- })
- //-->
- </script>
- </html>
暂时没有找到纯JQ的方法,只能采用事件处理机制来阻止冒泡。
可以在这里看效果 http://shawphy.com/demo/closediv/closediv.html
===================================
事后发现其实JQ已经为此做了兼容性,具体可以参考http://shawphy.com/40.html

