jQuery shortcut...LOGIN

jQuery shortcut events

Although we can use event handling functions to complete almost all operations on object events, jQuery provides encapsulation of common events. For example, the two methods click() and click(fn) corresponding to click events are used to trigger single clicks respectively. Click event and set click event.

Set click event:

$("#testDiv").click(function(event) { alert("test div clicked ! "); });

Equivalent to:

$("#testDiv").bind("click", function(event) { alert("test div clicked ! "); });

Trigger click event:

$("#testDiv").click();

Equivalent to

$("#testDiv").trigger("click");

Note that the equivalent here is trigger instead of triggerHandler.

This type of method is called Event Helpers in jQuery in English. I couldn't find a good translation method, so I called it "shortcut method" according to the function. We are collecting good translation names!

The following is jQuery List of shortcut methods:

Since they are all corresponding events, I won’t write explanations and examples anymore.

##dblclick( fn )error( )error( fn )focus( )focus( fn )##keydown( )keydown( fn )# # # mousedown( fn )#  mouseenter( fn )#  #mouseover( fn )#  mouseup( fn )#  resize( fn )
NameDescriptionExample
blur( )
##blur( fn )
change( )
change( fn )
##click( )
click( fn )
dblclick( )
keypress( )
keypress( fn )
#keyup( )
keyup( fn )
load( fn )
##mouseleave( fn )
# #mousemove( fn )
#mouseout( fn )
###### #scroll( fn )###  
select( )  
select( fn )  
submit( )  
submit( fn )  
unload( fn )  
Next Section
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>click事件</title> <style type="text/css"> div{ width:200px; height:200px; border:5px solid green; } </style> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("div").text("这是后来添加的内容"); }) $("p").dblclick(function(){ $("button").click(); }) }) </script> </head> <body> <div></div> <p>双击我触发click事件</p> <button>点击触发事件</button> </body> </html>
submitReset Code
ChapterCourseware