2009-09-30 5 views
25

체크 박스 모음이 있습니다.jQuery에서 모든 체크 박스를 찾는다.

 <input id="1" class="paid" type="checkbox" /> 
<input id="2" class="paid" type="checkbox" /> 
<input id="3" class="paid" type="checkbox" /> 
<input id="4" class="paid" type="checkbox" /> 

모든 체크 박스가 선택되어 있는지 확인한 다음 확인하는 jQuery를 작성하고 싶습니다.

답변

60

:

if (!$('input.paid[type=checkbox]:not(:checked)').length) 
    do('stuff'); 

이 선택하지 않은 것을 어떤, 그리고이없는 경우 물건을 할 경우는 확인합니다 (즉, 그들은 모두 체크).

+1

동일한 작업을 수행하는 현대적인 방법 –

2

가 나는 are 기능 JQuery와의 좋은 기능이있을 것이라고 생각 :

jQuery.fn.are = function(selector) { 
return !!selector && this.filter(selector).length == this.length; 
}; 

사용법 :

if($('input.paid[type=checkbox]').are(':checked')) 

예 :이 기능을 발견

http://jsfiddle.net/9s2vA/

http://api.jquery.com/is/ Tgr이 작성했는데, 이것이 존재하는지 확인하고있었습니다.

관련 문제