BelowCode, Onclick is executed first, and then event monitoring is executed:
< Html >
< Head >
< Title > JK Test </ Title >
< Meta Content = "Text/html; charsets = UTF-8" HTTP-equiv = Content-Type >
< Script SRC = "Http://s0.qhimg.com/lib/qwrap/110.js" Type = "Text/JavaScript" > </ Script >
< Style >
Div { Border : 1px solid balck ; Padding : 5px ; Margin : 2px ; }
</ Style >
</ Head >
< Body >
< Div ID = "Div1" Onclick = "Alert (1 );" > The native fireevent of div1 is to run onclick and then listeners.
</ Div >
</ Body >
< Script Type = "Text/JavaScript" >
VaR Fun = Function (E ){
Alert ( ' Hello ' );
};
W ( ' # Div1 ' ). Addeventlistener ( ' Click ' , Fun). Fire ( ' Click ' ); // QW calls native methods.
</ Script >
</ Html >
The execution sequence of jquery is the opposite:
< Html >
< Head >
< Title > JK Test </ Title >
< Meta Content = "Text/html; charsets = UTF-8" HTTP-equiv = Content-Type >
< Script SRC = "Http://s0.qhimg.com/lib/jquery/172.js" Type = "Text/JavaScript" > </ Script >
< Style >
Div { Border : 1px solid balck ; Padding : 5px ; Margin : 2px ; }
</ Style >
</ Head >
< Body >
< Div ID = "Div2" Onclick = "Alert (2 );" > Div2 jquery: Run listeners first and then onclick
</ Div >
</ Body >
< Script Type = "Text/JavaScript" >
VaR Fun = Function (E ){
Alert ( ' Hello ' );
};
$ ( ' # Div2 ' ). BIND ( ' Click ' , Fun). Trigger ( ' Click ' );
</ Script >
</ Html >
I scanned the JQ trigger implementation and did not figure out what the purpose was.