2012-03-07 18 views
4

選擇所有輸入標籤如何在沒有一定的屬性,並檢查選擇的所有輸入標籤中的每個輸入值jQuery中不爲空在沒有一定的屬性jQuery中

的Html

<input type="text" maxlength="255" value="" id="UserName" class="form-error" > 
<input type="text" maxlength="255" value="" id="Password" class="form-error"> 
<input type="text" maxlength="255" value="" id="Group" class="form-error" inputname="test" > 
<input type="text" maxlength="255" value="" id="Aka" class="form-error" inputname="money" > 

我想選擇所有的輸入從當前頁面不具有屬性作爲'inputname'。

喜歡的東西

在javascript中

var inputs = $('input:not(:has(>[inputname]))'); 

jQuery.each(inputs, function(input) { 
     if (input.value == '') { 
    $(input).next().removeClass('displayNone'); 
     return false; 
    } 
}); 
+0

[jQuery獲得所有沒有class屬性的div的可能的重複](http://stackoverflow.com/questions/1962247/jquery-get-all-divs-which-do-not-have-class-attribute ) – ManseUK 2012-03-07 10:16:33

回答

4

我相信你想

var inputs = $('input:not([inputname])'); 

Live example

+0

是否有可能在$('input:not([inputname] [type =「hidden」])')中使用多個選擇器? – 2012-03-07 10:19:56

+1

@Jusnit:[':not'只需要一個「簡單選擇器」](http://www.w3.org/TR/css3-selectors/#negation)。所以你把它們串起來,例如'$( '輸入:否([inputname]):不使用(類型= 「隱藏」])')'。 – 2012-03-07 10:21:16

-4

使用此 VAR輸入= $( 「:輸入」);

+0

我想要所有的輸入,但不包含屬性inputname – 2012-03-07 10:15:36

1

$( '輸入:不使用(inputname])')應該做的伎倆?

+1

當您看到您發佈了重複答案時,最好將其刪除。 – 2012-03-07 10:49:25