How to stop event propagation with inline onclick attribute?

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

Consider the following:

13条回答
  •  猫巷女王i
    2020-11-22 00:35

    Why not just check which element was clicked? If you click on something, window.event.target is assigned to the element which was clicked, and the clicked element can also be passed as an argument.

    If the target and element aren't equal, it was an event that propagated up.

    function myfunc(el){
      if (window.event.target === el){
          // perform action
      }
    }
    

提交回复
热议问题