JQuery中click() 和onclick()区别

1、onclick是绑定事件,告诉浏览器在鼠标点击时候要做什么

2、click()方法的主要作用是触发调用click方法元素onclick事件。

3、当click()被点击时,首先执行的是对应元素的onclick()函数,然后再是click(),示例如下:

JS代码 test.js:

$("#testclick").click(function(){ console.log("$("#testclick").click");
});

function test123(){
  console.log(
"function test()");
}
 1 <!DOCTYPE html>
 2 <html>
 3   <head>
 4     <title>TestJS.html</title>
 5     
 6     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 7     <meta http-equiv="description" content="this is my page">
 8     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 9     
10     <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
11 
12     
13   </head>
14   
15   <body>
16     This is my HTML page. <br>
17     <h1>Test html</h3>
18     <div>
21         <input type="button" onclick="test123();" class="input1" id="testclick" value="test_button"/>
22     </div>
23     
24     <!-- JS-->
26     <script src="js/lib/jquery.js"></script>
27     <script src="js/test.js"></script>
28     <!-- <script src="js/test2.js"></script> -->
29   </body>
30 </html>

结果:

  控制台打印出的顺序是:

  function test()

  $("#testclick").click

原文地址:https://www.cnblogs.com/dbj66/p/9071862.html