写表单验证时把每个验证都写的是input onblur事件,
出现一个问题,如果用户直接按那个a标签提交就不走每个input onblur事件,
难道我要重新写每个事件吗?
跟怎样给这个a标签加个点击事件?
$("#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("");
}
});
....
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不保证有效,可以试试:
其实,最好的办法是,在提交之前在做一次所有的验证
框架
用个框架jQuery Validation,分分钟搞定
no框架
不想用框架,那么你的代码需要优化
HTML结构
重复的结构太多,css写在行内,混乱不堪,建议调整
js
你只贴了一个验证码的代码,如果没看错的话,这样的代码至少还有三个,重复的内容太多,建议调整
像这种校验,还是建议你用框架。不用框架的话,写起来蛋疼。以上代码纯属参考!