How do I handle a click anywhere in the page, even when a certain element stops the propagation?

后端 未结 8 1765
臣服心动
臣服心动 2020-12-04 23:51

We are working on a JavaScript tool that has older code in it, so we cannot re-write the whole tool.

Now, a menu was added position fixed to the bottom and the clien

相关标签:
8条回答
  • 2020-12-05 00:37
    document.body.addEventListener("keyup", function(event) {
      if (event.keyCode === 13) {
      event.preventDefault();
      console.log('clicked ;)');
    }
    });
    

    DEMO

    https://jsfiddle.net/muratkezli/51rnc9ug/6/

    0 讨论(0)
  • 2020-12-05 00:38

    What you really want to do is bind the event handler for the capture phase of the event. However, that isn't supported in IE as far as I know, so that might not be all that useful.

    http://www.quirksmode.org/js/events_order.html

    Related questions:

    • jQuery equivalent of JavaScript's addEventListener method
    • Emulate W3C event capturing model in IE
    0 讨论(0)
提交回复
热议问题