2009-09-15 21 views
10

ile devre dışı bırakma Aynı tablo içindeki bir köprüyü tıklatırken bir tablo hücresindeki tüm onay kutularını devre dışı bırakmam gerekir.Bir tablo içindeki tüm onay kutularını jquery

Tablonun içine yerleştirilmiş tüm onay kutularını seçmek için aşağıdaki jue kodu kullanıyorum.

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

Bazı nedenlerden dolayı bu kod çalışmıyor.

Birisi bana nasıl düzeltileceğini gösterebilir mi?

cevap

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

Eğer tablo için bir kimliği varsa

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

Birinin doğru yazması gerektiğini ve 'doğru' olmadığını fark ettim. Bu çalışır: $ ('tablo girişi [type = onay kutusu]'). Attr ('disabled', true) ama bu değil: $ ('table input [type = checkbox]'). Attr ('disabled', 'true'); – gpasse

+0

Yardım etmeme yardım etmemi sağladı. Teşekkür ederim. +1 – SearchForKnowledge

6

Devre Dışı Bırakma?

$("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 
}); 

veya Checked?

$("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

Kodunuz çok daha basit olabilir:

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

olabilir:

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

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

veya onları kontrol etmek:

Sonra onları devre dışı bırakmak için

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

veya işaretlerini kaldırmaktır:

$el.removeAttr('checked'); 

veya bunları etkinleştirmek için:

$el.removeAttr('disabled'); 
0

bakın ayrıca: selector/checkbox

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

// Etkin/Devre Dışı Tüm Onay kutuları

$('#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

Bu benim çözüm

// 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

olduğunu ------------------ ------------- Aşağıdaki HTML Kodu ------------------------------

<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 Kodu aşağısı -----------------------------

+0

Merhaba, butonuna bastıktan sonra, bu JS işlevi çağırıldığında dört onay kutusunun da devre dışı bırakılacağını göreceksiniz. Teşekkürler. –

İlgili konular