Jquery Events
In JavaScript, events are invoked in the same way as OnClick, onmouseover, and so on, using events in jquery without writing the previous on
Bind () method
Binding an event to an element
$ ("#id"). Bind ("click",function() { //// for ID binding Click event alert ("OK"
Events that are bound using the bind () method are multicast event delegates, that is, events that are defined again do not overwrite the previous event
// you can execute two events $ ("#id") sequentially. Bind ("click",function() {alert ("1");}); $ ("#id"). Bind ("click",function() {alert ("2")});
One () method
Binding One-time events
// A single-click operation will no longer execute $ ("#id") the next time. One ("click",function() { alert ("a"); return false ;});
Unbind () method
Delete event, unbind
// Delete all events of ID // Delete all click events for ID
Quick Events
JavaScript events are removed on basic support
Click () method
Click events
// If the function body is not written, the event is immediately triggered by $ ("#id"). Click (function() { // This is a click event });
Dbclick () method
Double-click event
// Trigger Event $ ("#id"). Dbclick (function() { // double-click to execute });
Focus () method
Get focus
// Trigger $ ("#id"). Focus (function() { // get focus after execution });
Blur () method
Lose focus
// triggers the loss of focus event $ ("#id"). blur (function( ) {// lose focus after execution });
Change () method
When changing
// triggers the Change event $ ("#id"). Changes (function() {// change after execution });
MouseOver () method
Mouse Move in
$ ("#id"). MouseOver (); $ ("#id"). MouseOver (function() {});
Mouseout () method
Mouse move out
$ ("#id"). Mouseout (); $ ("#id"). Mouseout (function() {});
Submit () method
Submit Form
$ ("#id"). Submit (); $ ("#id"). Submit (function() {});
Hover () method
Used to solve the problems of mouseover and mouseout
// two function corresponding to move in and move out $ ("div"). Hover (function() { $ ("div"). HTML ("Ah ah ah ah ah oh, run, he's coming." );},function() { $ ("div"). html ("cried, scared to the end, finally gone!") ")});
Toggle () method
Execute each function sequentially, if execution is done repeatedly
$ ("#div"). Toggle ( function() { $ ("#div"). CSS ({"width": "100px" }) , function () { $ ("#div"). CSS ({"width": "200px" }); }, function() { $ ("#div"). CSS ({"width": "300px" });
Jquery Event Object
The Jquery event merges different browser differences, such as event.target can be used in all browsers to get the trigger without judging the browser's use of srcelement.
$ ("#div"). Click (function(e) { // return event name click // return event source who triggered the // alert (e.screenx); //... Wait for the event in JS });
27. Jquery Events