2011-06-23 83 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

相關問題