zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    洛谷P2146 [NOI2015]软件包管理器
    洛谷P3038 [USACO11DEC]牧草种植Grass Planting
    洛谷P2831 愤怒的小鸟
    洛谷P1084 疫情控制
    洛谷P3258 [JLOI]2014松鼠的新家
    洛谷P1084 运输计划
    洛谷P2051 [AHOI2009]中国象棋
    洛谷P1438 无聊的数列
    洛谷P1312 Mayan游戏
    luogu P1038 神经网络
  • 原文地址:https://www.cnblogs.com/dbj66/p/9071862.html
Copyright © 2011-2022 走看看