$(function () {
$("#data_table tr:gt(0)").click(function () {
console.log($(this).find(":checkbox").prop("checked"))
if ($(this).find(":checkbox").prop("checked"))// 此处要用prop不能用attr,至于为什么你测试一下就知道了。
{
$(this).find(":checkbox").removeAttr("checked");
// $(this).find(":checkbox").attr("checked", 'false');
}
else
{
$(this).find(":checkbox").prop("checked", true);
}
});
})
上转与:http://blog.csdn.net/easyboot/article/details/54629884
如果你是bootstrap datatable可以:
jq 怎么点击table的一行任意地方后,选中checkbox
$("body").delegate('#phoneObjectList tr', 'click', function () {
console.log($(this).find(":checkbox").prop("checked"))
if ($(this).find(":checkbox").prop("checked"))// 此处要用prop不能用attr,至于为什么你测试一下就知道了。
{
$(this).find(":checkbox").removeAttr("checked");
// $(this).find(":checkbox").attr("checked", 'false');
} else {
$(this).find(":checkbox").prop("checked", true);
}
});