$ (""). Example of the difference between click and onclick

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.