• 按键事件,提交事件,选择与改变事件


    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>聚焦离焦事件</title>
     </head>
     <script type="text/javascript">
     <!--
    function fun(obj,e){
        //拿到按键的asc码
        var key = e.keyCode;
        obj.value = key;
    }
     //-->
     </script>
    
     <body>
     <input type="text" name="" onkeypress = "fun(this,event)"> <!--显示按键的ascii-->
     </body>
    </html>

     提交事件

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>提交事件</title>
     </head>
     <script type="text/javascript">
     <!--
    function check(form){
        //拿到文本框中的内容
        var txt = form.username.value;
        //判断内容
        if(txt == ""){
            document.getElementById("sname").innerHTML = "<font color = red>姓名必填</font>";
            form.username.focus();
            return false;
        }
        return true;
    }
    
    
     //-->
     </script>
    
     <body>
        <form method = "post" action="2.html" onsubmit = "return check(this)">
            姓名:<input type="text" name="username"><span id="sname"></span><br>
                 <input type="submit" value="提交">
        </form>
     </body>
    </html>


    选择与改变事件

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>选择与改变事件</title>
     </head>
     <script type="text/javascript">
     <!--
        function fun(obj){
            alert(obj.value);
        }
    
        function fun2(v,index){
        
            alert(v + "--" + index);
        }
     //-->
     </script>
     <body>
      <input type="text" name="" onselect="fun(this)" on>
      <select onchange = "fun2(this.value, this.selectedIndex)">
            <option value="中国">中国</option>
            <option value="美国">美国</option>
            <option value="朝鲜">朝鲜</option>
      </select>
     </body>
    </html>

  • 相关阅读:
    实现一个最简单的flask应用程序
    python常识
    Flex布局
    ES6的promise的学习
    通过正则获取url参数
    dom0级事件和dom2级事件
    sea.js总结
    跨域的几种方式
    人生苦短,生命也就一次,机会也就一次
    新开的博客先和大家打个招呼吧!
  • 原文地址:https://www.cnblogs.com/taiguyiba/p/6188571.html
Copyright © 2020-2023  润新知