2016-12-01 66 views
0

我想是能夠搜索未禁用的複選框(屬性disable沒有被設置爲"disabled"HTML搜索由兩個屬性

我的功能就是下面我能夠找到的所有複選框,但我。不知道如何尋找未禁用複選框:

MarkAllColumns = function() { 

if (MarkAll === true) { 
    $("#tblArticlesSearch input[type=checkbox]").prop('checked', true); 
} 
else { 
    $("#tblArticlesSearch input[type=checkbox]").prop('checked', false); 
} 

}

我想屬性checked設置爲true只對未禁用複選框

回答

1

您可以使用:enabled選擇或:disabled選擇

$("#tblArticlesSearch input[type=checkbox]:enabled") 

$("#tblArticlesSearch input[type=checkbox]:not(:disabled)") 
+0

可能值得添加另一行顯示使用[':enabled' selector](https://www.w3.org/TR/css3-selectors/#enableddisabled)(這真的不值得再增加一個答案這樣做)。 –

+0

@Milind,非常感謝。精彩的回答。 – FrenkyB

1

另一種方式

$("#tblArticlesSearch input[type=checkbox]").prop('checked', !$('input[type=checkbox]').is(':disabled')); 

或在您的方式組合:not

$("#tblArticlesSearch input[type=checkbox]").prop('checked', !MarkAll);