首页 > 其他 > 详细

按键事件

时间:2016-12-16 22:58:57      阅读:189      评论:0      收藏:0      [点我收藏+]
<!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>

 

按键事件

原文:http://www.cnblogs.com/taiguyiba/p/6188571.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!