在事件捕获阶段(不是事件冒泡)绑定 jQuery 处理程序
我正在寻求对模糊/焦点事件实施事件委托,其方式与 怪异模式。正如 TFA 中所解释的,模糊和焦点事件不会冒泡,因此您不能在冒泡阶段对它们使用事件委托,但您可以在捕获阶段捕获它们(man,javascript events很奇怪)。
无论如何,据我所知,jQuery 事件都适用于冒泡阶段,或者至少是我一直使用它们的地方。我在 jQuery 文档中看不到有关这种方式或另一种方式的任何信息,并且默认情况下使用 $('#foo').blur(blurHandler) 之类的东西似乎无法捕获它。
为了保持一致性,我宁愿坚持使用 jQuery;有什么办法可以做到这一点吗?
I'm looking to implement event delegation on blur/focus events, in a similar way to that suggested on quirksmode. As explained in TFA, blur and focus events don't bubble, so you can't use event delegation with them in the bubbling phase, but you can grab them in the capture phase (man, javascript events are weird).
Anyhow, as far as I can see, jQuery events all apply to the bubbling phase, or at least that's where I've always used them. I can't see any information on this one way or the other in the jQuery docs, and by default using something like $('#foo').blur(blurHandler) doesn't seem to capture it.
I would prefer to stick to using jQuery for consistency; is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望容器在后代
获得焦点或模糊时触发处理程序,请尝试使用
.focusin()
和.focusout()。
来自文档:
If you're saying that you want a container to trigger a handler when a descendant
<input>
gets focus or blur, try using.focusin()
and.focusout()
.From the docs: