jquery validation是否支持分步验证,例如,我已经实现了一个包含20个问题的调查问卷,在一个表单中逐步显示和隐藏每个问题(继续使用按钮)。当按下按钮时,会显示下一个问题。
我想我必须触发对点击事件的验证,并打开对当前问题的验证。
发布于 2014-10-20 22:20:32
尝试使用this代码。
Html:
<div class="Steps Step_1">
<h1>Step 01</h1>
<input id="txtStep_1" type="text" value="" />
<button id="btnNext" data-next="Step_2">Next</button>
</div>
<div class="Steps Step_2" style="display: none;">
<h1>Step 02</h1>
<input id="txtStep_2" type="text" value="" />
<button id="btnNext" data-next="Step_3">Next</button>
</div>
<div class="Steps Step_3" style="display: none;">
<h1>Step 03</h1>
<input id="txtStep_3" type="text" value="" />
<button id="btnNext">Next</button>
</div>Javascript:
var current = 1;
$('button').on('click', function() {
if (!window["ValidateStep_" + current]())
alert('fill form..');
current++;
$('.Steps').hide();
$('.Step_' + current).show();
})
window.ValidateStep_1 = function() {
return true;
}
window.ValidateStep_2 = function() {
return true;
}
window.ValidateStep_3 = function() {
return false;
}https://stackoverflow.com/questions/26467526
复制相似问题