jQuery设置带有两个类的验证错误框 [英] jQuery Setting a validation error box with two classes
问题描述
我的代码中有一个,我有一个特定的textarea
我正在使用主.error
类,另一个有.textAreaError
放置了错误框,但我不确定如何配置要在此特定框中加载的textarea错误.
I have an with my code and I have one particular textarea
that I am using the main .error
class and another .textAreaError
that places the error box were I want it but I am unsure how I would configure the textarea error to load in this specific box.
从上一个问题开始,我得到了以下jQuery行function(error, element) { error.appendTo(element.siblings("label")); }
,但不确定如何将其应用于下面的代码.
From a previous question I was given the following jQuery line function(error, element) { error.appendTo(element.siblings("label")); }
but I am unsure how to work it into the code below.
jQuery:
jQuery(document).ready(function() {
//Home Validation
onfocusout: true,
$("#quote").validate({
rules:{
companyName:{
required: true,
url: true
}
}
});
HTML:
<div class="error textAreaError">Error Here</div>
推荐答案
通过查看文档对于validate插件,看来您可以使用使用function(error,element)的errorPlacement参数来控制错误的位置.代码看起来像这样:
From looking at the documentation for the validate plugin, it looks like you can control the position of the error with the errorPlacement argument which uses function(error, element). The code would look something like this:
jQuery(document).ready(function() {
//Home Validation
$("#quote").validate({
onfocusout: true,
rules:{
companyName:{
required: true,
url: true
}
},
errorPlacement: function(error, element) {
if (element.is("textarea"))
error.appendTo(".textAreaError");
else
error.appendTo(".generalError");
}
});
});
您必须为常规错误框提供generalError类.或者,提供错误框ID并引用错误框ID(例如"#textAreaError"和"#generalError").
You'd have to give the general error box the generalError class. Or, give the error boxes id's and refer to those instead (e.g. "#textAreaError" and "#generalError").
这篇关于jQuery设置带有两个类的验证错误框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!