本文介绍了如何使错误信息淡入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码进行表单验证
im using this code for form validating
$(document).ready(function(){
// Place ID's of all required fields here.
required = ["name", "email", "country", "message",];
// If using an ID other than #email or #error then replace it here
email = $("#email");
errornotice = $("#error");
// The text to show up within a field when it is incorrect
emptyerror = "Please enter a value in field";
emailerror = "Please enter a valid e-mail.";
$("#theform").submit(function(){
//Validate required fields
for (i=0;i<required.length;i++) {
var input = $('#'+required[i]);
if ((input.val() == "") || (input.val() == emptyerror)) {
input.addClass("needsfilled");
input.val(emptyerror);
errornotice.fadeIn(750);
} else {
input.removeClass("needsfilled");
}
}
// Validate the e-mail.
if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
email.addClass("needsfilled");
email.val(emailerror);
}
//if any inputs on the page have the class 'needsfilled' the form will not submit
if ($(":input").hasClass("needsfilled")) {
return false;
} else {
errornotice.hide();
return true;
}
});
// Clears any fields in the form when the user clicks on them
$(":input").focus(function(){
if ($(this).hasClass("needsfilled") ) {
$(this).val("");
$(this).removeClass("needsfilled");
}
});
});
问题是如何让空错误和电子邮件错误消失?
i尝试添加此代码但它没有用:emptyerror.hide()。fadeIn(750);
我也尝试过括号中的emptyerror,或者像这个$(#emptyerror)
但是没有一个工作
任何想法?
the question is how can i make the emptyerror and emailerror fade in?
i tried adding this code but it didnt work: emptyerror.hide().fadeIn(750);
I also tried putting the emptyerror in brackets, or like this $("#emptyerror")
but none of them worked
any ideas?
推荐答案
这篇关于如何使错误信息淡入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!