如何在单击父时更改Checkbox属性
我需要你的小建议。
在里面的复选框属性的onclick应该改变。里面也有一个
HTML代码:
这是我的代码:
$('.sample').click(function() { row =$this.parents("td"); row.siblings().find("input:checkbox").attr("checked","checked" ); } }); });
请有人帮帮我!
$('TABLE > TBODY > TR').click(function() { $('input:checkbox', $(this)).prop("checked", "checked"); });
尝试
$('TABLE TBODY TR').click(function() { $(this).find('input:checkbox').attr("checked", "checked"); });
关于使用jQuery操作复选框有一个不错的SO线程
在此查看示例
如果您尝试切换选定的状态,请使用以下命令:
jQuery 1.6+
$('table tbody tr').click(function() { $('input:checkbox', this).prop('checked', function(index, oldValue) { return !oldValue; }); });
jQuery pre-1.6
$('table tbody tr').toggle(function() { $('input:checkbox', this).attr('checked', 'checked'); }, function() { $('input:checkbox', this).removeAttr('checked'); });
将属性值更改为"checked"
应该有效。
$('TABLE TBODY TR').click(function() { $(this).find('input:checkbox').attr("checked", "checked"); });
看到它在行动 。
试试这个
$(this).find('input:checkbox').attr("checked","checked");
使用jQuery 1.6,代码更具可读性:
$("table tbody tr").click(function(){ $(this).find("input[type='checkbox']").prop("checked",true); });
这对我来说很好:
$('#checkall').click(function() { $('#cause').children().each(function() { $(this).find("input[type='checkbox']").prop("checked", $('#checkall').prop("checked")); }); });
只需在没有每个function的情况下使用它/检查/取消选中所有元素