2016-12-27 11 views
0

属性がchecked="checked"に設定されているものだけを選択しますが、すべてを選択します。条件がすべてのチェックボックスを選択した場合

<input class="chxbx" type="checkbox" checked="checked"> 
<input class="chxbx" type="checkbox"> 
<input class="chxbx" type="checkbox"> 

のjQuery:

$(".chxbx").each(function(i, e){ 
    if($(".chxbx").prop("checked", true)){ 
    // this should select only the the input tag with 
    //checked="checked" but it selects all checkboxes 
    }  
}) 
+1

質問は何ですか? – Satpal

+0

こんにちはSatpal、条件がすべてのチェックボックスを選択すると、SatPalが有効になります。 htmlでは最初の入力タグのみがチェックされ、条件が最初のタグだけがチェックされていることを示す必要がある場合はjquery – Deke

答えて

3

あなたは正しく.eachを使用していません。

は次のようになります。その代わり

$(".chxbx").each(function(){ 

    if($(this).is(":checked")){ 

    // this should select only the the input tag with 
    //checked="checked" but it selects all checkboxes 
    }  
}); 

または:

$(".chxbx:checked").each(function(){ 

// this should select only the the input tag with 
//checked="checked" but it selects all checkboxes 
}); 
関連する問題