码迷,mamicode.com
首页 > 其他好文 > 详细

按键事件

时间:2016-12-16 22:59:58      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:author   rds   set   key   style   ntb   javascrip   font   htm   

<!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>

 

按键事件

标签:author   rds   set   key   style   ntb   javascrip   font   htm   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!