2013-08-22 90 views
5

可以說我有一組輸入窗體上:選擇除所有輸入隱藏(但有一個例外)

<form id="myform"> 
    <input type="checkbox" id="goat_1"> 
    <input type="checkbox" id="goat_2"> 
    <input type="text" id="pig_3"> 
    <input type="hidden" id="cow_1"> 
    <input type="hidden" id="chick_3"> 
    <input type="hidden" id="duck_5"> 
</form> 

我想選擇所有的投入,除了type="hidden",但有一個例外,我確實希望任何以「鴨」開頭的隱藏輸入。我需要將這一切全部放在一個數組中,以便可以遍歷它。

所以前兩個部分很簡單:

$("#myform").find(":input").not("[type=hidden]").each(
              function() { alert("do stuff"); }) 

但有關異常的是什麼?

我正在尋找最乾淨的方式來做到這一點(更喜歡一行/語句)。

回答

7

嘗試

$("#myform").find(":input").not("[type=hidden]:not([id^='duck'])").each(function() { 
    alert("do stuff"); 
}); 
+0

+1,你去那裏! – vee

0

試試這個:

$('#myform > input').not(':hidden:not([id^=duck])').each(function (i, e) { 
    alert('This is my id: ' + e.id); 
}); 

工作在這個fiddle例子。

相關問題