你好,
当我提交表单时没有在表单中填写任何内容而没有检查我的验证功能时,这就是我在JQ中的代码,我在global中声明了要在函数提交中签出的变量,这些是什么问题?>
$(function() {
$('.names').hide();
$('.username').hide();
$('.email').hide();
$('.password').hide();
$('.co-password').hide();
var error_user = false;
var error_username = false;
var error_pass = false;
var error_email = false;
$('#registerForm').submit(function(){
error_user = false;
error_username = false;
error_pass = false;
error_email = false;
check_user();
check_username();
check_email();
check_pass();
confirm_password();
if(error_user === false && error_username === false &&
error_email === false && error_pass === false ){
alert('Successfully !');
$('#submitPass').html('Rigesteration Sucessfull!').css('color','green');
return true;
}else{
alert('Please fill the form !');
$('#submitPass').html('Please fill the form !').css('color','red');
return false;
}
});
});
关于一个功能的一些示例:
function check_user(){
var pattern = /^[a-zA-Z0-9]*$/;
var fname = $('#name').val();
if(fname.length <= 0){
$('.names').show();
$('#Ename').html('please enter your name');
$('#name').css('border-color','#f14343');
}
else{
if(pattern.test(fname) && fname !== ''){
$('.names').hide();
$('#name').css('border-color','#29f44b');
}else{
$('#Ename').html('The Name Shouldn\'t Contain Bad Char ');
$('.names').show();
$('#name').css('border-color','#f14343');
error_user = true;
}
}
}