zoukankan      html  css  js  c++  java
  • 页面内部DIV让点击外部DIV 事件不发生(阻止冒泡事件)

    如标题的情况,经常发生,尤其是在一些弹出框上面之类的。

    <script>
        function zuzhimaopao(){
            e.stopPropagation();
        }
    </script>

    一般的google浏览器添加上面此项就可以,但是发现在FF下并不工作,于是有了如下:

    function getEvent(){
            if(window.event)    {return window.event;}
                func=getEvent.caller;
                while(func!=null){
                 var arg0=func.arguments[0];
                 if(arg0){
                     if((arg0.constructor==Event || arg0.constructor ==MouseEvent
                        || arg0.constructor==KeyboardEvent)
                        ||(typeof(arg0)=="object" && arg0.preventDefault
                        && arg0.stopPropagation)){
                         return arg0;
                     }
                 }
                 func=func.caller;
            }
            return null;
        }
        //阻止冒泡
        function cancelBubble()
        {
            var e=getEvent();
            if(window.event){
                //e.returnValue=false;//阻止自身行为
                e.cancelBubble=true;//阻止冒泡
            }else if(e.preventDefault){
                //e.preventDefault();//阻止自身行为
                e.stopPropagation();//阻止冒泡
            }
        }

    只要在你的方法最后插入  

    cancelBubble();
    就可以了。
    很实用
  • 相关阅读:
    头文件<stdarg.h>
    头文件<signal.h>
    头文件<setjmp.h>
    头文件<math.h>
    头文件<locale.h>
    头文件<limits.h>
    头文件<ctype.h>
    头文件<assert.h>
    PHP error_reporting
    八大排序算法
  • 原文地址:https://www.cnblogs.com/Viagra/p/7419592.html
Copyright © 2011-2022 走看看