jquery多种形式的验证
我有一个格式如下的表单:
<form id="program" name="program method="get" action="process.jsp">
<div id="add">
some input box here...........
<input type="submit" name="action" value="Add">
</div>
<div id="exit">
some input box here...........
<input type="submit" name="action" value="Exit">
</div>
<div id="refuse">
some input box here...........
<input type="submit" name="action" value="Refuse">
</div>
</form>
我的 jquery 代码验证是:
$("#program").validate({
errorClass: "error",
rules: {
doentry: {
required: true,
date: true
},
doe: {
required: true,
date: true
},
dor: {
required: true,
date: true
},
cid: {
selectNone: true
}
}
});
其中 dor, doe, doentry 是一个 位于不同的 div 中,问题是当我单击提交时,一个当前可见(未隐藏)的 div,它还需要验证当前隐藏的其他 div 中的所有其他元素...我不想要!解决这个问题的最佳方法是什么,只需修改 jQuery..因此它只验证当前可见的 div 内的元素,而不是整个表单。
I have a form with the following format:
<form id="program" name="program method="get" action="process.jsp">
<div id="add">
some input box here...........
<input type="submit" name="action" value="Add">
</div>
<div id="exit">
some input box here...........
<input type="submit" name="action" value="Exit">
</div>
<div id="refuse">
some input box here...........
<input type="submit" name="action" value="Refuse">
</div>
</form>
My jquery code validation is:
$("#program").validate({
errorClass: "error",
rules: {
doentry: {
required: true,
date: true
},
doe: {
required: true,
date: true
},
dor: {
required: true,
date: true
},
cid: {
selectNone: true
}
}
});
where dor, doe, doentry is an <input>
that is in different div, the problem is when I click on submit, on a div that is currently visible (not hidden), it requires all the other elements in the other div's that is currently hidden to be validated as well... which I don't want! What's the best way to solve this just by modifying the jQuery.. so only it validates the elements that is inside a div that is currently visible and not the whole form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证插件有一个
ignore
选项,使用它使用:hidden
选择器忽略不可见的元素, 像这样:The validation plugin has an
ignore
option, use that with the:hidden
selector to ignore elements that aren't visible, like this: