我有一个表单,我正在使用jquery.validate。我最初使用一组规则和自定义消息调用验证...
$("#formName").validate( {
rules: {
myExistingInput: {
required: true
}
},
messages: {
myExistingInput: {
required: "Enter something"
}
},
ignore: null, // include hidden fields (see below)
submitHandler: function(form) {
// do stuff
},
invalidHandler: function(event, validator) {
// do stuff (some of the fields may have been hidden by a collapsible panel
// if there is an error on one of those fields, expand the panel so the error
// becomes visible)
}
});
稍后,我在表单中动态添加了字段,并为这些字段添加了规则...
$("#formName").append(...);
$("#newInputName").rules("add", {
required: true,
messages: {
required: "Enter something else"
}
});
如果我随后提交表单,我会在jquery.validate中收到一个错误...
检查元素调用时发生
异常,请检查‘newInputName’method.TypeError:无法获取未定义引用或空引用的属性'call‘
在浏览器中调试时,我可以看到错误是从"check“函数中抛出的,并且"method”变量被设置为"messages“。
如果我从对规则的调用中删除消息(“add”,...
$("#newInputName").rules("add", {
required: true
});
它按预期工作,但显然我现在没有自定义的错误消息。
我在这里看到了很多例子,这表明我的语法是正确的。有什么建议吗?
顺便说一句: jQuery验证插件- v1.11.0 - 2/4/2013
https://stackoverflow.com/questions/15482523
复制相似问题