我试图使用jQuery验证插件来制作一个带有制表符的多步骤表单,但当我试图循环所有输入时,我总是收到“元素未定义”错误。有什么建议么?我不明白什么是错的。我试过把复选框放在多个地方,它似乎随处可见(即不仅仅是在第二个标签)。jquery验证复选框“元素是未定义的”
var tabs = $("#tabs").tabs({
disabled: [1,2,3,4,5],
select: function(event, ui) {
var valid = true;
var current = $(this).tabs("option", "selected");
var panelId = $("#tabs ul a").eq(current).attr("href");
$(panelId).find("input").each(function(index, element) {
if (!validator.element(this) && valid) {
if(ui.index > current) {
valid = false;
}
else
{
//re-disable the next tab
}
}
});
return valid;
}
});
$(".nexttab").click(function() {
var selected = $("#tabs").tabs("option", "selected");
$("#tabs").tabs("enable", selected+1);
$("#tabs").tabs("option", "selected", selected + 1);
});
HTML部分:
<div id="general">
</div>
<div id="problemtab">
<p>
<input type="checkbox" name"response" id="response" value="agree" class="required"><label for="response">I Agree</label>
</p>
<p>
<a class="prevtab navbutton"><span>Prev</span></a>
<a class="nexttab navbutton"><span>Next</span></a>
</p
</div>
<div id="lasttab">
</div>
感谢您的帮助!
Edit:
It's giving me an error in jquery-validate.js:787
staticRules: function(element) {
var rules = {};
var validator = $.data(element.form, 'validator'); // <---- Error here
if (validator.settings.rules) {
rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
}
return rules;
},
编辑#2:元/本被定义为对象HTMLInputElement]
这里是我的验证:
var validator = $("#myForm").validate({
ignore : ['#tabs .inactive input'], // tells the validator to only validate elements on your current tab
errorElement: "div",
wrapper: "div", // a wrapper around the error message
errorPlacement: function(error, element) {
if (element.parent().hasClass('group')){
element = element.parent();
}
offset = element.position();
error.insertBefore(element)
error.addClass('message'); // add a class to the wrapper
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
error.css('top', offset.top);
}
});
validator.element的声明在哪里? – 2011-04-15 05:39:06
@James:它在标签代码下面。它应该在上面吗?我不明白它为什么可以与非复选框输入一起工作。添加到我的帖子,对此感到抱歉。 – Jordan 2011-04-15 06:03:59