jQuery 验证插件:可以使用 "depends" 标签 return 一个 int 吗?
jQuery Validate plugin: Can using the "depends" tag return an int?
这是我的规则对象中的规则声明示例:
myFieldObj: {
maxlength: {
depends: function(element) {
if($("#intranetApplication").is(":checked") == true) {
return 32;
}
else if($("#internetApplication").is(":checked") == true) {
return 25;
}
}
}
}
基本上,我的代码是根据用户对某个问题的选择来设置要验证的 myFieldObj 的最大长度。但是,此代码似乎不起作用。我知道我可以 return 使用此代码的布尔值(例如):
myFieldObj: {
maxlength: {
depends: function(element) {
if($("#intranetApplication").is(":checked") == true) {
return TRUE;
}
else if($("#internetApplication").is(":checked") == true) {
return FALSE;
}
}
}
}
但这也适用于整数吗?
只需删除 depends
属性 并将函数用作方法的参数...
myFieldObj: {
maxlength: function(element) {
if ($("#intranetApplication").is(":checked")) {
return 32;
}
else if ($("#internetApplication").is(":checked")) {
return 25;
}
}
}
此外,由于 .is()
已经 returns 一个布尔值,因此无需将其与 true
进行比较。
这是我的规则对象中的规则声明示例:
myFieldObj: {
maxlength: {
depends: function(element) {
if($("#intranetApplication").is(":checked") == true) {
return 32;
}
else if($("#internetApplication").is(":checked") == true) {
return 25;
}
}
}
}
基本上,我的代码是根据用户对某个问题的选择来设置要验证的 myFieldObj 的最大长度。但是,此代码似乎不起作用。我知道我可以 return 使用此代码的布尔值(例如):
myFieldObj: {
maxlength: {
depends: function(element) {
if($("#intranetApplication").is(":checked") == true) {
return TRUE;
}
else if($("#internetApplication").is(":checked") == true) {
return FALSE;
}
}
}
}
但这也适用于整数吗?
只需删除 depends
属性 并将函数用作方法的参数...
myFieldObj: {
maxlength: function(element) {
if ($("#intranetApplication").is(":checked")) {
return 32;
}
else if ($("#internetApplication").is(":checked")) {
return 25;
}
}
}
此外,由于 .is()
已经 returns 一个布尔值,因此无需将其与 true
进行比较。