2011-06-23 84 views
0

我有一个要求,取消所有复选框与单个单选按钮。我的HTML代码是如何使用jQuery单选按钮检查属性取消所有复选框

<table> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"></td></tr> 
</table> 

我的jQuery代码如下,请更正它中的错误。

$('TABLE TBODY TR').each(function() 
    { 
    $(this).children('td:eq(2)').append("<input type='radio' class=rad>"); 
    }); 
$('TABLE TBODY TR').each(function() 
    { 
    $(this).find('input:radio').change(function() 
    { 
    if($(this).attr('checked')) 
    { 
     $(this).siblings(':checkbox').attr('checked',true); 
      $(this).parents('tr').children('td').find('input:checkbox').not('$(this).siblings(':checkbox')').attr('checked',false); 
    } 
    }); 
    }); 
    $('TABLE TBODY TR').each(function() 
    { 
    $(this).find('input:checkbox').not('td:eq(2) :checkbox').change(function() 
    { 
    if($(this).attr('checked')) 
    { 
     $(this).parents('tr').children('td').find('input:checkbox').attr('checked',false); 
     $(this).parents('tr').children('td').find('input:radio').attr('checked',false); 

    } 
    }); 
    }); 

谢谢:-)

回答

1

如何取消与使用jQuery一个单选按钮,检查财产所有复选框?

此代码将在无线电更改设置复选框,以反映其状态。

$('#toggle').change(function() { 
    $('#container :checkbox').prop('checked', this.checked); 
}); 
+0

残友请看看我的代码,并纠正它 – Reddy

相关问题