zoukankan      html  css  js  c++  java
  • Javascript 中的 绑定事件方法

    js绑定事件2种方法:

    1. <input type = "button" onclick="clickHandler()">

    2. 该方法必须掌握

    <input type = "button" id="button1">

    <script type = "text/javascript">

    var v = document.getElementById("button1");

    v.onclick=clickHandler; //注意,没有括号

    </script>

    <!DOCTYPE html>
    <html>
      <head>
        <title>js16.html</title>
        
      </head>
      
      <body>
        <script type="text/javascript">
            function getEvent(event)//event是浏览器自动生成的
            {
                alert("事件类型:" + event.type);
            }
            document.write("单击...");
            document.onmousedown = getEvent; //这里没有括号,不可以写成 getEvent(event);
        </script>
      </body>
    </html>

    再看一个:

    <!DOCTYPE html>
    <html>
      <head>
        <title>js17.html</title>
    
      </head>
      
      <body>
        <input type="button" id="button1" value = "button1 ">
        <script type="text/javascript">
            var v = document.getElementById("button1");
            v.onclick = function clickHandler()
            {
                alert ("button is clicked.");
            }
        </script>
      </body>
    </html>

    安安

  • 相关阅读:
    小程序自定义组件(3)子向父传参
    postgresql插件安装
    二进制减法的实现
    mysql锁表问题
    mysql查看修改参数
    众数问题-找出超过一半的数
    只出现一次的数
    元素最大间距离
    第一个缺失数字
    局部最小值位置
  • 原文地址:https://www.cnblogs.com/backpacker/p/2613775.html
Copyright © 2011-2022 走看看