How to stop event propagation with inline onclick attribute?

前端 未结 13 2088
情书的邮戳
情书的邮戳 2020-11-21 23:46

Consider the following:

13条回答
  •  盖世英雄少女心
    2020-11-22 00:29

    Keep in mind that window.event is not supported in FireFox, and therefore it must be something along the lines of:

    e.cancelBubble = true
    

    Or, you can use the W3C standard for FireFox:

    e.stopPropagation();
    

    If you want to get fancy, you can do this:

    function myEventHandler(e)
    {
        if (!e)
          e = window.event;
    
        //IE9 & Other Browsers
        if (e.stopPropagation) {
          e.stopPropagation();
        }
        //IE8 and Lower
        else {
          e.cancelBubble = true;
        }
    }
    

提交回复
热议问题