0

这是我的编码,

<tr class="ar">
   <td>
        <input type="checkbox" class="cbx">
   </td>    
   <td>
        <span class="spc">book</span>
   </td> 
</tr>
<tr class="ar"></tr>

我想要做什么,如果单击复选框或跨度(在 first 内tr),我想将一个类切换到 second tr。此外,如果复选框已经被选中,那么我需要在单击其中任何一个时取消选中。

4

5 回答 5

3
$('td input[type=checkbox], td span').click(function(){
    $(this).closest('tr')
        .find('input[type=checkbox]')
        .prop("checked", false)
        .end()
        .next()
        .toggleClass('yourclass');
});
于 2013-01-07T11:14:58.377 回答
2

尝试这个

$(".cbx2").click(function(){
  $(this).closest("tr.ar").next().toggleClass("toggled_class");
});

$(this).closest("tr.ar")将为您提供该对象最接近的具有类的父tr元素,并将获得该类型的下一个元素,即您的第二个元素。ar.nexttr

于 2013-01-07T11:19:58.740 回答
0

试试这个......如果你想取消选中复选框......

$('#your_checkbox_id').live('click' , function() {
    if($('#your_checkbox_id').is(':checked')) {
        $('#your_checkbox_id').removeAttr('checked');
        $(this).next().toggleClass('class_name');
    }
});
于 2013-01-07T11:17:03.300 回答
0
$('.cbx, .spc').click(function(e){
    $('.cbx').prop('checked', false); // uncheck everything

    $(this).toggleProp(checked, $(this).prop('checked')) // check/uncheck current
           .closest('.ar').toggleClass('yourClass'); // toggle class on next tr
});
于 2013-01-07T11:45:28.323 回答
0

尝试使用这个:http://jsfiddle.net/kPJJf/

$('td input[type=checkbox], td span').click(function () {
       $(this).parents('tr').next('tr').find('span').toggleClass('spc');
   if($(this).parents('tr').next('tr').find('input[type="checkbox"]').is(':checked')==false){
      $(this).parents('tr').next('tr').find('input[type="checkbox"]').prop('checked', true);
   }else{
      $(this).parents('tr').next('tr').find('input[type="checkbox"]').removeAttr('checked');
   }
});
于 2013-01-07T11:45:34.093 回答