Jor*_*dan 4 javascript validation checkbox jquery
我正在尝试使用jQuery Validation插件制作带有制表符的多步骤表单,但是当我尝试遍历所有输入时,我不断收到"元素未定义"错误.有什么建议?我不明白什么是错的.我已经尝试将复选框放在多个位置,它似乎发生在任何地方(即不仅仅是在第二个最后一个选项卡).
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);
});
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
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;
},
Run Code Online (Sandbox Code Playgroud)
编辑#2:element/this定义为[object 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);
}
});
Run Code Online (Sandbox Code Playgroud)
您忘记了复选框的name属性的等号,因此未设置name属性.
name"response" 应该 name="response"
我昨天注意到jquery.validate需要一个元素名称才能工作,否则会抛出此错误.
| 归档时间: |
|
| 查看次数: |
3392 次 |
| 最近记录: |