jquery multiple event handlers(jquery 多个事件处理程序)
问题描述
我已经根据我正在处理的最新项目中的类名定义了事件处理程序.
I have defined event handlers according to their classnames in the latest project that I'm working on.
例如.所有具有类名foo"的元素都应以特定方式响应更改事件.并且所有类名为bar"的元素都应该以其他方式响应.
for ex. all element with the class name "foo" should respond in a particular way on change event. and all elements with the class name "bar" should respond in some other way.
现在我的一些元素属于两个类,即 class="foo bar",它们应该以两种方式响应.目前,只有一个事件处理函数被调用.
Now some of my elements fall under both classes i.e. class="foo bar" and they should respond in both ways. Right now, only one of the event handler function is being called.
如何让两个响应同时执行.
How can I make both the responses execute simultaneously.
推荐答案
这取决于你如何绑定事件.如果您通过 jQuery 绑定它们而不是通过 x.onchange = function() { ... }
覆盖处理程序 - 所有绑定的事件处理程序都将被执行.这是因为 jQuery queues 事件处理程序而不是 覆盖 以前的绑定.
It depends on how you are binding the events. If you are binding them via jQuery and not overwriting the handlers via x.onchange = function() { ... }
- all the bound event handlers will get executed. This is because jQuery queues the event handlers instead of overwriting the previous binding(s).
检查此 fiddle
以查看 多个事件被触发时间>:
和
检查此 fiddle
以查看事件处理程序如何被覆盖导致只有最后一个绑定的处理程序触发
这篇关于jquery 多个事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jquery 多个事件处理程序


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01