2016-10-25 39 views
-1

當這個社區在編譯某個輸入標記時顯示「下一個」按鈕時,我有很大的幫助。 我用這個代碼:編輯輸入類型文本,複選框,收音機和選擇標記時顯示按鈕

$('.name').keyup(function() { 
    $('#next1').toggle(this.value != ''); 
}); 

#next1 { 
    display: none; 
} 

但我怎麼能如果我的網頁是更復雜的修改呢?

例如在這裏我有一些複選框,收音機輸入和選擇標籤。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    <input class="name" type="text" name="name" /> 
    <input type="text" name="phone" placeholder="Phone" /> 
    <label class="radio-inline"><input type="radio" name="internet" value='Y'>Y</label> 
    <label class="radio-inline"><input type="radio" name="internet" value='N'>N</label> 
    <label for="degree">Degree</label><br/> 
     <input type="checkbox" name="degree" value="degree"> Degree 
<select id='city' name='city' title='City' class='required1Sel form-control' > 
    <option value=''></option> 
    <option value='1'>NY</option> 
    <option value='2'>LA</option> 
    <option value='3'>MIAMI</option> 
</select> 
    <div id="next1"> 
     <input type="button" name="next" class="next action-button" value="Next" /> 
    </div> 
+0

所以你要下按鈕,只有當所有的控件具有值可見...吧?? – gkb

+0

只有當所有控件的值都是「phone」以外。 我有更多的領域,但不是全部都是必需的。 – maures

回答

0

對於選擇或複選框,您可以使用change()函數。

$('#city').change(function() { 
    $('#next1').toggle(this.value != ''); 
}); 

看到這個的jsfiddle:https://jsfiddle.net/fpwo8e7e/1/

+0

它的工作,但如果我有更多的選擇標記,我使用類(required1Sel喜歡這個例子),它顯示我下一個按鈕,而我編譯只有一個這樣的。 我試過這段代碼 $(」。required1Sel ')。每個(函數(){ \t \t $('。required1Sel ')。改變(函數(){ \t \t \t $(' #下一個')切換(THIS.VALUE =! ''); \t \t}); \t \t \t \t \t }); – maures

+0

但它不適用於 – maures

+0

您需要爲每個輸入添加「標誌」。 onchange(var changed1 = true)。如果(changed1&changed2&changed 3 ...)然後showbutton。或者,也許你可以檢查值是否不等於'' – Sergiodiaz53

相關問題