JS阻止事件冒泡

 

    <input type="button" id="js_button" />
    <div id="js_div" style="width: 100px; height: 100px;  display: none">
    </div>
    <script type="text/javascript">
        $(document).ready(
     function () {
         $("#js_button").click(function (e) {
             $("#js_div").show(300);
             /*阻止冒泡事件*/
             e = window.event || e;
             if (e.stopPropagation) {
                 e.stopPropagation();
             } else {
                 e.cancelBubble = true;
             }

         });
         $("#js_div").click(function (e) {
             /*阻止冒泡事件*/
             e = window.event || e;
             if (e.stopPropagation) {
                 e.stopPropagation();
             } else {
                 e.cancelBubble = true;
             }
         });
         $(document).click(function () {
             $("#js_div").hide(300);
         });
     }
     );
    </script>
posted @ 2014-09-03 15:48  释迦苦僧  阅读(279)  评论(0编辑  收藏  举报