简体   繁体   English

在JavaScript中,是否可以在IE上注册一个事件侦听器,以捕获页面上所有的更改,焦点和模糊事件?

[英]In JavaScript is it possible on IE to register one event listener to capture all the change, focus, and blur events on the page?

  • In non-IE browsers: 在非IE浏览器中:
    • The change event bubbles, so you can catch it when it gets to document in the bubbling phase. change事件起泡,因此您可以在冒泡阶段对其进行document时捕获它。
    • The focus and blur events don't bubble, but you can catch them on the capture phase with one event listener on document . focusblur事件不会冒泡,但是您可以在捕获阶段使用document上的一个事件侦听器来捕获它们。
  • On IE: 在IE上:
    • None of those 3 events bubble (including the change event, which is not spec compliant). 这3个事件均不会冒泡(包括不符合规范的change事件)。
    • There is no capture phase on IE. IE上没有捕获阶段。

So, as far as I know, the only way on IE is to register an event listener for change , focus , and blur on every form control. 因此,据我所知,IE上的唯一方法是为每个表单控件上的changefocusblur注册一个事件侦听器。 This operation can be expensive when you have a lot of controls. 当您有很多控件时,此操作可能会很昂贵。 But is there a better way? 但是有更好的方法吗?

jQuery 1.4定义了“ focusin”和“ focusout”来捕获所有浏览器的焦点和模糊事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM