实现目的:当时去焦点时,触发事件监测用户名是否符合规范!不符合则用户名文本框获得焦点且选上!
问题描述:当不符合规范时,用户名文本框选上了~但是用TAB或鼠标点击是用户名文本框失去焦点时,除了自身被选上,其他跳转的文本框也选上了!
以下是代码:
  html:
        用户名:<input  type="text" id="username"/><br />
密  码:<input  type="text" id="password"/><br />
确认密码:<input  type="text" id="confirmpassword"/><br />
备  注:<input  type="text" id="re"/><br />
<input  type="button" value="提交"  id="test"/>
  js:
var reg="";
$(function() {
$("#username").focus();
    $("#username").blur(function(){
       reg=/^[\w]{6,20}$/;
       if(reg.test(this.value))
       {
            return true;
       } else{
            alert("用户名格式不对!请重新输入!");
            this.focus();
            this.select();
            return false;
       }
    });
    $("#test").click(function(){
        $("input[@type=text]").each(function(){
            if(this.value==""||this.value==null)
            {
                alert("请输入信息!");
                this.focus();
                
                return false;
            }else{
                return true;
            }
        });
    });
});