开发者

jQuery - call a function anytime a user changes any form input?

I have a page that has multiple forms. Anytime the user clicks an input or modifies text in an input I would like a function to be called. Any ideas on how to do this efficiently and in a way where it doe开发者_StackOverflowsn't require the form IDs?


JavaScript events bubble up. So how about:

$('form').change(function() {
    // do something
}).click(function() {
    // do something
});

In each case you can query for the element that triggered the event and do what you please.


$('form input').each(function() {
     var val = this.value;
     $(this).click(function() { }
     $(this).blur(function() {
     }

});

You can also use delegate for better performance. It would help seeing your source and your exact needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜