如图所示,我想实现点击checkbox对应的行时,checkbox就能选中,如果是第一行的话,下面全选,下面是我查到的代码,但是这种方式只能对第一张表格起效,网页中有很多这样的表格,该怎么做?
$(".table tr").slice(1).click(function () {
var chks = $("input[type='checkbox']",this);
var tag = $(this).attr("tag");
if(tag == "selected"){
$(this).attr("tag","");
chks.prop("checked",false);
}else{
$(this).attr("tag","selected");
chks.prop("checked",true);
}
});
要么给其他表格也加上 class='table' 的样式,要么 $('table tr')