How to stop event propagation with inline onclick attribute?

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

Consider the following:

相关标签:
13条回答
  • 2020-11-22 00:48

    This worked for me

    <script>
    function cancelBubble(e) {
     var evt = e ? e:window.event;
     if (evt.stopPropagation)    evt.stopPropagation();
     if (evt.cancelBubble!=null) evt.cancelBubble = true;
    }
    </script>
    
    <div onclick="alert('Click!')">
      <div onclick="cancelBubble(event)">Something inside the other div</div>
    </div>
    
    0 讨论(0)
提交回复
热议问题