JQuery supports global events. These are used for things like "ajaxComplete" and similate. I've also made my own globale events like that from time to time, and what it does "behind the scenes", that JQuery don't show me (the developer), and that I really don't care about is that it calls that event on every item in the JQuery-cache. However, I came up with a project where subglobal events would really simplify my work. For instance, say that I want th开发者_开发问答e event to fire on all childelements (recursively, without having to manually write a recursive function-loop) of a given element. For instance, I want the event to fire on all inputs on the form #form1. How would I go about doing this?
To fire an event, you can use the .trigger()
method:
$('#form1 :input').trigger('customevent');
精彩评论