仅当我点击该行但我想以两种方式点击它时,我才能检查该复选框。 这是我使用的方法:
$("table tr").click(function(){
var id=$(this).attr("id");
//This is because i dont want first row to be able to select
if(typeof(id)!="undefined"){
if($("#select-"+id).attr("checked")!="checked")
$("#select-"+id).attr("checked","checked");
else
$("#select-"+id).removeAttr("checked");
}
});
同样在这里你可以实时查看它sabrio.eu5.org/admin.php 用户名:admin 密码:admin
答案 0 :(得分:3)
我最好的猜测是你的TR点击功能正在取消被点击的复选框的默认行为。因此,当您单击复选框时,它就像被点击两次一样。
尝试向您添加点击事件复选框,如下所示......
$("[type='checkbox']").click(function(e) {
e.stopPropagation();
});
您需要将选择器更改为适合您的html
的内容答案 1 :(得分:1)
这有用吗
$("table tr").click(function(){
var checkbox = $(this).find(':checkbox');
checkbox.attr('checked', !checkbox.attr('checked'));
});