【示例】
-
HTML
<form action="" method="post"> <input id="one" type="text" onfocus="true" /> <input type="text" /> <input type="button" onclick="gogo();" value="提交" /> </form>
-
JS
if(event.keyCode==13&&event.srcElement.type!='button'&&event.srcElement.type!='reset'&&event.srcElement.type!='textarea'&&event.srcElement.type!='') event.keyCode=9; $(function(){ //加载页面时光标自动聚焦到 第一个文本框 window.onload=function(){ document.getElementById("one").focus(); } ; //触发提交按钮后检验,默认失败,使光标聚焦在第一个文本框 function gogo(){ alert("hello"); document.getElementById("one").focus(); } });