Http://www.jb51.net/article/55650.htm
HTML code
?
12345678910111213 |
<script type=
"text/javascript"
>
$(
function
(){
$(
"#btn4"
).click(
function
(){
$(
"#btn3"
).click();
});
});
function change(){
alert(
"onclick"
);
}
</script>
<button id=
"btn3" onclick=
"change()"
>dd</button>
<button id=
"btn4"
>ee</button>
|
Difference:
1.onclick is a binding event that tells the browser what to do when the mouse clicks
The click itself is the method that triggers the OnClick event, and the onclick event is triggered whenever the click () method of the element is executed. As shown in the appeal code, when the ' EE ' button is clicked, the ' DD ' onclick event will be triggered (normally press ' DD ' button to trigger the ' DD ' onclick event) because
?
123 |
$( "#btn4" ).click( function (){ $( "#btn3" ).click(); }); |
When you click the ' EE ' button, the code internally invokes the ' DD ' click () method, which triggers the ' DD ' onclick event.
The primary role of the 2.click () method is to trigger the call to the click Method Element onclick event. Also, if the click Method defines the following code
?
123 |
$( "#btn3" ).click( function (){ alert( "*****" ); }); |
The function code in the click Method executes after the OnClick event has finished executing, at which point the click Method acts as an append event. Examples are as follows
HTML code
?
1234567891011 |
<script type=
"text/javascript"
>
$(
function
(){
$(
"#btn3"
).click(
function
(){
alert(
"aa"
);
});
});
function change(){
alert(
"bb"
);
}
</script>
<button id=
"btn3" onclick=
"change()"
>dd</button>
|
The pop-up sequence is first ' BB ' and then ' AA '.
$ (""). Example of the difference between click and onclick