您现在的位置:首页 >> 前端 >> 内容

表单的焦点顺序和对应enter键提交

时间:2012/11/22 15:21:54 点击:

  核心提示:表单的焦点tap键顺序:tabindex决定,如果值缺省,择按顺序用户:input name=Text1 type=text tabindex=1 /密码:input name=Password1 t...

表单的焦点tap键顺序:tabindex决定,如果值缺省,择按顺序
 用户:<input name="Text1" type="text" tabindex="1" />
 密码:<input name="Password1" type="password" tabindex="2" >
对应onsubmit事件即可:
[html] 
 <form action="<%=basePath%>common/userlogin.action" method="post" name="loginform" id="loginform" onsubmit="return subUser();"> 
<input src="<%=basePath%>scxt/image/home08.jpg" type="image"/> 
</form> 

注意return的用法。
js: www.2cto.com
[javascript] 
function subUser(){ 
          var username=$("#uname").val(); 
          var password=$("#upwd").val(); 
          var checkCode=$("#checkCode").val(); 
          if(username==""){ 
            $("#msg").html("请输入用户名!"); 
            $("#uname").focus(); 
             return false; 
          }else if(password==""){ 
            $("#msg").html("请输入密码!"); 
            $("#upwd").focus(); 
              return false; 
          }else if(checkCode==''){ 
            $("#msg").html("请输入验证码!"); 
            $("#checkCode").focus(); 
             return false; 
          }else{ 
            document.loginform.submit(); 
             return false; 
          } 
          return false; 
    } 

表单获取焦点事件:
$(”#nameInput”).focus()

作者:网络 来源:不详