gpt4 book ai didi

jquery - 所需的表单验证规则取决于

转载 作者:行者123 更新时间:2023-12-01 03:20:03 25 4
gpt4 key购买 nike

有人能给我介绍一下如何使用验证规则必需取决于吗?我有一些部分代码,但不确定它是如何工作的。

$("#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 - 所需的表单验证规则取决于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10905676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com