2014-10-20 2 views
0

jquery validate는 단계별 유효성 검사를 지원합니까? 즉, 각 질문을 단계적으로 표시하고 숨기는 단일 폼에서 20 개의 질문으로 설문지를 구현했습니다 (버튼으로 계속 진행). 버튼을 누르면 다음 질문이 표시됩니다.jQuery의 단계별 유효성 검사

나는 clicked-event에 대해 유효성 검사를 실행하고 현재 질문에 대한 유효성 검사를 전환해야한다고 생각합니다.

+0

그것은 유효한 '와 함께 할 수있어()'하지만 당신은 당신이 전체 응답을 받게 될 경우 현재 코드를 첨부해야합니다. –

답변

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> 

자바 스크립트 :

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; 
} 
관련 문제