jQuery 验证 - 元素未定义
我正在使用 jquery.validation 插件来验证我在表单上的输入
,如下所示:
$(document).ready(function () {
jQuery(function () {
// You can specify some validation options here but not rules and messages
jQuery('form[id="reservationForm"]').validate({ ignore: ":not(:visible)" });
$("#adult1Birthdate").mask("9999-99-99");
$("#reservationPersonBirthdate").mask("9999-99-99");
$("#adult1Firstname").rules("add", { required: true, minlength: 2, messages: { required: '<span style="color:Red">Pole wymagane</span>'} });
});
});
但是我收到以下错误:
元素未定义
以下行中的
var settings = $.data(element.form, 'validator').settings;
:我做错了什么?
**EDIT**
当我使用 jquery.validation 时,以下代码也不起作用
$(document).ready(function () {
$(function () {
$('a[id^="regionDetails"]').click(function () {
var vid_id = $(this).attr("id").replace("regionDetails", "#regionDetailsArea");
$('div[id^="regionDetailsArea"]').hide();
$(vid_id).show();
return false;
});
});
});
I am using a jquery.validation plugin to validate my inputs on the form
I use it as follows:
$(document).ready(function () {
jQuery(function () {
// You can specify some validation options here but not rules and messages
jQuery('form[id="reservationForm"]').validate({ ignore: ":not(:visible)" });
$("#adult1Birthdate").mask("9999-99-99");
$("#reservationPersonBirthdate").mask("9999-99-99");
$("#adult1Firstname").rules("add", { required: true, minlength: 2, messages: { required: '<span style="color:Red">Pole wymagane</span>'} });
});
});
I get the following error however:
element is undefined
in the following line:
var settings = $.data(element.form, 'validator').settings;
What am I doing wrong?
**EDIT**
Also the following code does not work when I use jquery.validation
$(document).ready(function () {
$(function () {
$('a[id^="regionDetails"]').click(function () {
var vid_id = $(this).attr("id").replace("regionDetails", "#regionDetailsArea");
$('div[id^="regionDetailsArea"]').hide();
$(vid_id).show();
return false;
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您调用
.rules()
的元素确实存在,jquery.validate
在添加规则时不会检查它,并且在所描述的行处惨败,只是因为该元素未定义。Make sure the element you're calling
.rules()
on does exist,jquery.validate
doesn't check for it when adding rules and fails miserably at the described line, simply because the element is not defined.如果您使用
$
,请勿使用jQuery
。试试这个:If you're using
$
, don't usejQuery
. Try this:我注意到,当我出现此错误时,我在表单中未定义的规则中调用了一个输入。或者,反之亦然。
I've noticed that when this error appears for me, I have an input being called in rules that I don't have defined in my form. Or, vice versa.