简体   繁体   English

JQuery,为同一个事件添加两个处理程序

[英]JQuery, add two handlers for the same event

I have several text inputs in my page. 我的页面中有几个文本输入。 They have different classes added to them. 他们添加了不同的类。 Depending on the class they each have, I add an onchange event handler. 根据它们各自的类,我添加一个onchange事件处理程序。 Everything worked OK, until they all shared one common class, then I add common onchange handler again. 一切正常,直到他们共享一个公共类,然后我再次添加常见的onchange处理程序。 The first oen gets overwritten. 第一个被覆盖。

Is there a way to add another handler and not overwrite the precious one? 有没有办法添加另一个处理程序,而不是覆盖宝贵的处理程序?

They should not get overwritten. 他们不应该被覆盖。

You should be able to do: 你应该能够做到:

$('.className').change(function(){
    alert('here')
})

$('.className').change(function(){
    alert('over here')
})

And you should see both alerts 你应该看到两个警报

See fiddle: http://jsfiddle.net/maniator/JEyTM/ 请参阅小提琴: http//jsfiddle.net/maniator/JEyTM/

All right, I resolved my issue following this tutorial . 好的,我在本教程后解决了我的问题。

It was actually related to a this Farbtastic bug 它实际上与这个Farbtastic虫有关

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

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