Html code
<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>the difference:
1.onclick is a binding event that tells the browser what to do when clicking the mouse
Click itself is a method that triggers the onclick event. As long as the element's click() method is executed, the onclick event will be triggered. As shown in the appeal code, when the 'ee' button is clicked, the 'dd' onclick event will be triggered (normally, pressing the 'dd' button will trigger the 'dd' onclick event). The reason is that
$("#btn4").click(function(){$("#btn3").click();});When clicking the 'ee' button, the 'dd' click() method is called internally, which triggers the 'dd' onclick event.
2. The main function of the click() method is to trigger the onclick event to call the click method element. In addition, if the following code is defined in the click method
$("#btn3").click(function(){alert("***");});The function code in the click method will be executed after the onclick event is executed. At this time, the click method plays the role of appending events. Example:
Html code
<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 order of the pop-up box is first 'bb' and then 'aa'.