2009-09-15 8 views
10

同じテーブル内のハイパーリンクをクリックすると、テーブルセル内のすべてのチェックボックスを無効にする必要があります。jqueryでテーブル内のすべてのチェックボックスを無効にする

次のjqueryコードを使用して、テーブル内にネストされたすべてのチェックボックスを選択しています。

$el = $(this).parents('table:eq(0)')[0].children('input[type="checkbox"]'); 
$($el).attr('checked', true); 

何らかの理由で、このコードが機能しません。

誰でも私にそれを修正する方法を教えてもらえますか?

答えて

25
$('table input[type=checkbox]').attr('disabled','true'); 

あなたがテーブル

$('table#ID input[type=checkbox]').attr('disabled','true'); 
+3

私は、真実ではなく「真実」と書くべきであることに気付きました。 attr( 'disabled'、 'true'); $( 'table input [type = checkbox]')。attr( 'disabled'、true) ); – gpasse

+0

私を助けて、質問を書くことから私を救った。ありがとうございました。 +1 – SearchForKnowledge

6

無効にしますか?

$("a.clickme").click(function(){ 
    $(this)     // Link has been clicked 
    .closest("td")   // Get Parent TD 
    .find("input:checkbox") // Find all checkboxes 
    .attr("disabled", true); // Disable them 
}); 

またはチェック済み?

$("a.clickme").click(function(){ 
    $(this)     // Link has been clicked 
    .closest("td")   // Get Parent TD 
    .find("input:checkbox") // Find all checkboxes 
    .attr("checked", false); // Uncheck them 
}); 
2

のIDを持っている場合、あなたのコードはずっと簡単になります

$el = $(this).parents('table:eq(0)')[0].children('input[type="checkbox"]'); 

は次のようになります。

$el = $(this).parents('table:first :checkbox'); 

$el.attr('disabled', 'disabled'); 

たり、それらをチェックする:

そして、それらを無効にする

$el.attr('checked', 'checked'); 

たり、それらをオフにする:

$el.removeAttr('checked'); 

たり、それらを有効にする:

$el.removeAttr('disabled'); 
0

参照してください。 :selector/checkbox

jQuery("#hyperlink").click(function() { 
    jQuery('#table input:checkbox').attr('disabled', true); 
    return false; 
}); 
0

//有効/無効すべてのチェックボックス

$('#checkbox').click(function() { 

    var checked = $(this).attr('checked'); 
    var checkboxes = '.checkboxes input[type=checkbox]'; 

    if (checked) { 
     $(this).attr('checked','checked'); 
     $(checkboxes).attr('disabled','true'); 
    } else { 
     $(this).removeAttr('checked'); 
     $(checkboxes).removeAttr('disabled'); 
    } 
}); 
0

これが私の解決策

// Action sur le checkbox 
     $("#tabEmployes thead tr th:first input:checkbox").click(function() { 
      var checked = $(this).prop('checked'); 
      $("#tabEmployes tbody tr td:first-child input:checkbox").each(function() { 
       $(this).prop('checked',checked); 
      }); 
     }); 
0

です------------------ -------------下記のHTMLコード------------------------------

<table id="myTable"> 
    <tr> 
     <td><input type="checkbox" checked="checked" /></td> 
     <td><input type="checkbox" checked="checked" /></td> 
     <td><input type="checkbox" /></td> 
     <td><input type="checkbox" /></td> 
    </tr> 
</table> 

<input type="button" onclick="callFunction()" value="Click" /> 

---------------- ---------------下のJQueryコード-----------------------------

<script type="text/javascript"> 
    function callFunction() { 
     //: 
     $('table input[type=checkbox]').attr('disabled', 'true'); 
    } 
</script> 
+0

こんにちは、ボタンをクリックすると、このJS関数が呼び出されると、4つのチェックボックスがすべて無効になることがわかります。ありがとう。 –

関連する問題