jQuery-所需的表单验证规则取决于 [英] jquery - form validate rules required depends
本文介绍了jQuery-所需的表单验证规则取决于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以给我介绍如何使用validate
,rules
,required
,depends
的入门知识.
我有一些部分代码,但不确定如何工作.
Can somebody give me a primer on how to use the validate
, rules
, required
, depends
.
I have some partial code but not sure how it works.
$("#form2").validate({
rules: {
firstname: {
required: {
depends: function () {
$(this).val($.trim($(this).val()));
return true;
}
},
minlength: 2
},
推荐答案
$("#form2").validate({
rules: {
firstname: { //This rule applies to the $('#form2 input[name="firstname"]') selector
required: { //This can be a true/false boolean, string, or a complex field using depends.
depends: function () { //depends takes a function pointer that
//returns a value, informing the rule
//if it is required. In this case, always true.
$(this).val($.trim($(this).val()));
return true;
}
},
minlength: 2 // the minimum length of text in the field is 2 characters.
},
这篇关于jQuery-所需的表单验证规则取决于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文