我需要验证多步骤表单。这样做有什么好的插件吗?
例如:
$(function() {
$('#MoveStep1').click(function() {
$("#step1").validate();
});
});
#step1
是一个字段集。
答案 0 :(得分:1)
如果您对4行快速入侵感到满意,我只是建议这样做
//untested but you'll get the gist, you may need a slight variation on this
$("#step1").wrap('<form id="tmp-form"></form>');
$("#tmp-form").validate();
$("#step1").insertBefore("#tmp-form");
$("#tmp-form").remove();
基本思想是以临时形式包装它。验证。去掉。重复。
Benefits: use a validation plugin you already know and is well-tested. you don't need to change any existing validation rules Cons: possible undesired layout effects depending on you style markup maybe others? once again, not tested just a quick thought
答案 1 :(得分:0)
这样的事情怎么样:
//setup validation, don't validate if the control is: ignored, inside an ignored container, or hidden
$("form").validate({ ignore: ".ignore, .ignore *, :hidden" });
$("#MoveStep1").click(function() {
//assuming each step is in a container with the class Step
$(".Steps:not(#step1)").addClass(.ignore);
$("form").valid();
$(".Steps").removeClass(.ignore);
});