javascript 回车替换成TAB

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
 
 
<script lang="javascript">
 
function check()     
{
    var name = document.getElementById("name").value;     
    var password = document.getElementById("password").value;
    
    alert("name="+name+" and password="+password);
     
}    
 
// rewrite the 'onkeydown' event to make sure 'Enter' key can be used as 'Tab' in some needed circumstances.  It work fine on both IE and non-IE browsers.
document.onkeydown=function(evt)
{
    var isie = (document.all) ? true : false;
    var key;
    var srcobj;
    // if the agent is an IE browser, it's easy to do this.
    if (isie) {
        key = event.keyCode;
        srcobj=event.srcElement;
    }
    else {
        key = evt.which;
        srcobj=evt.target;
    } 
    if(key==13 && srcobj.type!='button' && srcobj.type!='submit' &&srcobj.type!='reset' && srcobj.type!='textarea' && srcobj.type!='') {
        if(isie)
            event.keyCode=9;
        else {
            var el=getNextElement(evt.target);
            if (el.type!='hidden')
                ;   //nothing to do here.
            else
                while(el.type=='hidden')
                    el=getNextElement(el);
            if(!el)
                return false;
            else
                el.focus();
        }
    }
}
 
function getNextElement(field) {
    var form = field.form;
    for(var e = 0; e < form.elements.length; e++) {
        if (field == form.elements[e])
        break;
    }
    return form.elements[++e % form.elements.length];
}  
 
</script>                  
<body>                                   
<p><b>javascript 回车替换成TAB</b></p> 
<form>
<table width="20%">
  <tr>
    <td>
      name:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="name" size="12"> 
    </td>
  </tr>
  <tr>
    <td>
      password: <input type="password" size="12" id="password">
    </td>
  </tr>  
  <tr>
    <td>
        <input type="button" value="Submit" onclick="check()">
    </td>
  </tr> 
<table>
<form>
</body>                                    
                                    
</html>
                                    
</html>

 

转载于:https://www.cnblogs.com/gobuild/p/5962329.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值