写表单验证时把每个验证都写的是input onblur事件,
出现一个问题,如果用户直接按那个a标签提交就不走每个input onblur事件,
难道我要重新写每个事件吗?
跟怎样给这个a标签加个点击事件?
<form action="#" method="post">
<span class="errorMsg"></span>
<p>
<label>手机号码:</label>
<input id="form_phone" type="text" tabindex="1" autocomplete="off">
<em class='error' style="display: none;"></em>
<em class='success' style="display: none;"></em>
<span class="info_tips">注册成功后请直接用手机号登录</span>
<a href="javascript:;" id="sendsms" class="mt5 ml10 blue_big_btn" style="display:none;">发送验证码</a>
</p>
<p>
<label>短信验证码:</label>
<input id="phone_code" name="phone_code" type="text" tabindex="2" autocomplete="off">
<em class='error' style="display: none;"></em>
<em class='success' style="display: none;"></em>
<span class="info_tips" >请输入您收到的短信验证码</span>
</p>
<p>
<label>设置密码:</label>
<input id="psw1" name="password" type="password" tabindex="3">
<em class='error' style="display: none;margin-top: -15px;margin-left: 15px;"></em>
<em class='success' style="display: none;margin-top: -15px;margin-left: 15px;"></em>
<span class="info_tips pw_spec_tips">6-16位,字母(区分大小写)、数字、符号</span>
<span id="pw_strength"></span>
</p>
<p>
<label>确认密码:</label>
<input id="psw11" name="new_password" type="password" tabindex="4" disabled="">
<em class='error' style="display: none;"></em>
<em class='success' style="display: none;"></em>
<span class="info_tips">请再次输入您的密码</span>
</p>
<a id="confirm1" class="blue_btn">立即注册</a>
</form>
$("#phone_code").on("blur",function(){
if($(this).val() == ""){
$(this).next(".error").css("display","inline-block");
$(this).parent().find(".success").css("display","none");
$(this).parent().find(".info_tips").text("不能为空").css("color","#FF0000");
}
else if(!phone_code_reg.test($(this).val())){
$(this).parent().find(".success").css("display","none");
$(this).next(".error").css("display","inline-block");
$(this).parent().find(".info_tips").text("输入的短信验证码格式不正确").css("color",
"#FF0000");
}
else{
$(this).parent().find(".error").css("display","none");
$(this).parent().find(".success").css("display","inline-block");
$(this).parent().find(".info_tips").text("");
}
});
....
不保证有效,可以试试: