gpt4 book ai didi

jquery 验证器 addMethod 不起作用

转载 作者:行者123 更新时间:2023-12-01 08:02:02 26 4
gpt4 key购买 nike

经过一番努力,我完全无法让 addMethod 工作。

我的代码如下:

$("#submitform").validate(
{
rules: {
org_name: "required",
email_address: "required",
phone: "required",
abn: "required",
description: "required",
geocomplete: "required"
},
messages: {
org_name: "Required",
email_address: "Required",
phone: "Required",
abn: "Required",
description: "Required",
geocomplete: "Required"
},
submitHandler: function(event, validator) {


// submitForm();

},
invalidHandler: function(event, validator) {
//code..
}
});

添加方法

    $.validator.addMethod("org_name", function(value) {
// return this.optional(element) || value == params[0] + params[1];
console.log("hi" + value);alert('hi');
return false;
}, "Invalid");

和目标元素

<input id="org_name" name="org_name" type="text" class="input-xlarge ">

addMethod 函数没有被调用,没有错误,我对此不知所措?另一方面,“必需”验证在表单上正常工作,正如预期的那样,这是我第一次尝试这个插件。

最佳答案

使用如下规则,

 org_name: "org_name",

你的代码应该是这样的,

 $("#submitform").validate(
{
rules: {
org_name: "org_name",// input element: method name
email_address: "required",
phone: "required",
abn: "required",
description: "required",
geocomplete: "required"
},

关于jquery 验证器 addMethod 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19157045/

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