2014-10-20 168 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; 
}