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>

    安安

  • 相关阅读:
    PHP编码规范-笔记
    MySQL
    烧毁的诺顿
    页面查询案例(使用redis数据库)
    非关系型数据库-redis
    校验用户名是否存在
    使用Cookie实现浏览器显示上次登录时间
    Java文件下载
    随机验证码生成
    Response对象
  • 原文地址:https://www.cnblogs.com/backpacker/p/2613775.html
Copyright © 2011-2022 走看看