Original link: Http://outofmemory.cn/code-snippet/2123/jquery-zhuce-event-method
1. Use event names to bind, the available event names are
Change,Click,DblClick,Error,Focus,focusin,focusout,< Span class= "PLN" >keydown,keypress,keyup ,mousedown,mouseenter ,mouseleave,mousemove ,mouseout,mouseovermouseup,resize, Scroll,select,submit , unload
For example:
$(' #target '). Click(function() {alert(' #target元素绑定了click事件 ');});
2. Bind the event bind (TYPE,[DATA],FN) using the Bind method. The type parameter and the various event names described above for us, for example:
When each paragraph is clicked, its text pops up.
3. Using the on method to register the event, the on method is basically the same as the Bind method, in fact, the Bind method is best to invoke the on method to achieve
$('. SCV '). On(' click ',function() {$(this). Clone(true). AppendTo(' #container ');});
4. Even later add-on methods Live method
In the old jquery version, we had a way to handle event bindings for dynamically generated elements-live (), using the Live () method to apply the effects of the method bindings to existing or newly created DOM elements. The code is as follows:
$('. SCV '). Live(' click ',function() {$(this). Clone(). AppendTo(' #container ');});
5. One-time event-binding method A method that binds a single-pass event handler for each matching element's specific event (like click). When all paragraphs are clicked for the first time, all their text is displayed.
$("P"). One("click",function() {alert( this). Text()); });
"Go" jquery method for registering events