2014-10-20 126 views
0

jquery是否验证支持逐步验证,即我已经用单个表单中的20个问题实现了问卷调查,逐步显示并隐藏每个问题(继续使用按钮)。按下按钮时,显示下一个问题。jQuery验证逐步验证

我想我必须触发点击事件的验证并切换当前问题的验证。

+0

这是可能的'有效做到()'但是你如果你希望得到完整的答案附上您当前的代码。 – 2014-10-20 14:03:29

回答

0

尝试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; 
}