简体   繁体   中英

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. Everything worked OK, until they all shared one common class, then I add common onchange handler again. 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/

All right, I resolved my issue following this tutorial .

It was actually related to a this Farbtastic bug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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