gpt4 book ai didi

jquery - 验证器 $.validator.methods[method] 未定义

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

我继承了这个验证器表单代码,但收到此错误:

$.validator.methods[method] is undefined 

在其下面显示

'maxlength:$.validator.format("Please enter no more than {0} characters.")'

我读到这可能是拼写错误或调用的方法不存在。但看不到它..即使阅读远程数据元素也可能会导致问题,但将其取出会损坏。

编辑:我上传了没有压缩的js代码,错误指向这一行

var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );

代码:

$(document).ready(function(){
$("#regForm").validate({
rules:{
confirmemailaddress: {
equalTo: "#emailaddress"
},
password: {
password: "#username"
},
adminpassword: {
adminpassword: "#adminusrname"
},
retypepassword: {
equalTo: "#password"
},
retypenewpassword: {
equalTo: "#newpassword"
},
retypeadminpassword: {
equalTo: "#adminpassword"
},
interest2: {
notEqualTo: "#interest"
},
retypenewadminpassword: {
equalTo: "#newadminpassword"
},
emailaddress: {
remote: {
url: $("#validationUrl").val(),
type: "post",
data: {
emailaddress: function() {
return $("#emailaddress").val();
},
registrationtype: function() {
return $("#registrationtype").val();
},
userctx: function() {
return $("#userctx").val();
},
identityid: function() {
return $("#identityid").val();
}
}
}
},
username: {
remote: {
url: $("#validationUrl").val(),
type: "post",
data: {
username: function() {
return $("#username").val();
},
registrationtype: function() {
return $("#registrationtype").val();
},
userctx: function() {
return $("#userctx").val();
}
}
}
},
adminusrname: {
notEqualTo: "#username",
remote: {
url: $("#validationUrl").val(),
type: "post",
data: {
username: function() {
return $("#adminusrname").val();
},
registrationtype: function() {
return $("#registrationtype").val();
},
userctx: function() {
return $("#userctx").val();
}
}
}
},
oldauthusername: {
remote: {
url: $("#validationUrl").val(),
type: "post",
data: {
username: function() {
return $("#oldauthusername").val();
},
registrationtype: function() {
return $("#registrationtype").val();
},
userctx: function() {
return $("#userctx").val();
}
}
}
}
},
messages: {
instname:{
required: "Please specify the name of your institution"
},
firstname:{
required: "Please specify your First Name",
minlength: jQuery.format("At least {0} characters required!")
},
lastname:{
required: "Please specify your Name",
minlength: jQuery.format("At least {0} characters required!")
},
interest:{
required: "Please choose an interest area"
},
interest2:{
required: "Please choose a second interest area",
notEqualTo: "Please choose a different interest area to the above"
},
emailaddress:{
required: "We need your Email Address to contact you",
email: "Your Email Address must be in the format name@domain.com",
remote: jQuery.format("{0} is already in use")
},
confirmemailaddress:{
required: "Please confirm your Email Address",
email: "Your Email Address must be in the format name@domain.com",
equalTo: "Please enter the same Email Address as above"
},
username: {
required: "Please specify your User Name",
minlength: jQuery.format("At least {0} characters required!"),
remote: jQuery.format("{0} is already in use")
},
oldauthusername: {
required: "Please specify your User Name",
minlength: jQuery.format("At least {0} characters required!"),
remote: jQuery.format("{0} is already in use")
},
password: {
required: "Please specify your Password",
minlength: jQuery.format("At least {0} characters required!")
},
retypepassword: {
required: "Please retype your Password",
minlength: jQuery.format("At least {0} characters required!"),
equalTo: "Enter the same password as above"
},
adminusrname: {
required: "Please specify your User Name",
minlength: jQuery.format("At least {0} characters required!"),
remote: jQuery.format("{0} is already in use"),
notEqualTo: "Your username must be different to the institution username"
},
adminpassword: {
required: "Please specify your Password",
minlength: jQuery.format("At least {0} characters required!")
},
retypeadminpassword: {
required: "Please retype your Password",
minlength: jQuery.format("At least {0} characters required!"),
equalTo: "Enter the same Password as above"
},
retypenewpassword: {
required: "Please retype your New Password",
minlength: jQuery.format("At least {0} characters required!"),
equalTo: "Enter the same password as above"
},
termsandconditions: {
required: "Please tick the checkbox to confirm that you have read and agree to the terms and conditions before proceeding."
}
}
});

$("#ipmarker .asterix").hide();
$("#logincredmarker .asterix").hide();

$("#validateContact").click(function() {
var errors = false;
var firstError;
$(".contact .required").each(function() {
if(!$("#regForm").validate().element(this))
{
if (! errors)
firstError = $(this);
errors = true;
}
});
$(".contact .email").each(function() {
if(!$("#regForm").validate().element(this))
{
if (! errors)
firstError = $(this);
errors = true;
}
});
if(errors)
{
firstError.focus();
return false;
}
else
{
$(".contact").hide();
$(".authentication").show();
if($('#usrname').is(':checked'))
$("#usrname").parent("legend").parent("fieldset").find(".regInput").find(".optRequired").addClass("required");
$(".regStep2").removeClass("linkDisabled");
scroll(0,0);
return false;
}
});

var validateAuthenticationStep = function(){
if ( ( $("#oldauthhiddenusername").val() != null && $("#oldauthhiddenusername").val() != '')
|| ( $("#oldauthusername").val() != null && $("#oldauthusername").val() != '')
|| ( $("#iprange").val() != null && $("#iprange").val() != '')
|| ( $("#username").val() != null && $("#username").val() != '')
|| ( $("#externalid").val() != null && $("#externalid").val() != '')
)
{
var errors = false;
$(".authentication .required, .authentication .checkIP, .authentication .email").each(function() {
if(!$("#regForm").validate().element(this))
{
if (! errors)
firstError = $(this);
errors = true;
}
});
if(errors)
{
firstError.focus();
return false;
}
else
return true;
}
else
{
$(".authenticationselectionerror").show();
scroll(0,0);
}
}

$("#validateAuthentication").click(function() {
if($("#username").val()!="") {
$("#password").addClass("required");
$("#retypepassword").addClass("required");
}
else
{
$("#password").removeClass("required");
$("#retypepassword").removeClass("required");
}

if (validateAuthenticationStep())
{
$(".authentication").hide();
$(".authenticationAdmin").show();
$(".regStep3").removeClass("linkDisabled");
}
return false;
});

$("#validateUpdateAuthentication").click(function() {
if(validateAuthenticationStep())
$("#regForm").submit();
return false;
});





});

最佳答案

您收到此错误是因为您调用了不存在的规则...

rules: {
//other rules,
interest2: {
notEqualTo: "#interest"
},
}

notEqualTo 不是此插件中包含的有效规则。您必须删除它或使用 plugin's built-in addMethod() method 创建名为 notEqualTo 的新规则。 。像这样的事情...

jQuery.validator.addMethod('notEqualTo', function(value, element, param) {
return value != jQuery(param).val();
}, 'Must not be equal to {0}.' );

关于jquery - 验证器 $.validator.methods[method] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14896205/

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