首页 > 代码库 > javascript 回车替换成TAB
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: <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>
javascript 回车替换成TAB
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。