87,984
社区成员
发帖
与我相关
我的任务
分享
$("#tdClassInfo").on("click", "tr", function () {
var input = $(this).find("input");
if ($(input).attr("checked")) {
$(input).removeAttr("checked");
}
else
{
$("#tdClassInfo tr").find("input").each(function () {
$(this).removeAttr("checked");
});
$(input).attr("checked", true);
}
});
$("#tdClassInfo").on("click", "tr", function () {
var input = $(this).find("input");
$(input).click();
});
$("#tdClassInfo").on("click", "tr input", function () {
alert(2222) //这个alert一直在弹出来,死循环的
});
<td>
<div style="position:relative;width: 100%; height: 100%;top: 0px; left: 0px;">
<input name="_id" type="radio" value="1"/>
<div style="position:absolute;z-index: 2;width: 100%; height: 100%;top: 0px; left: 0px;opacity: 1;"></div>
</div>
</td>
加个透明层放到单选/复选框的上面,让他点不到就可以了$("#tdClassInfo").on("click", "tr", function (e) {
if(e.target.type==='checkbox'){
return;
}
var input = $(this).find("input");
if ($(input).attr("checked")) {
$(input).removeAttr("checked");
}
else
{
$("#tdClassInfo tr").find("input").each(function () {
$(this).removeAttr("checked");
});
$(input).attr("checked", true);
}
}); $('#tdClassInfo :checkbox').on("change",function() {
if ($(this).attr('checked')) {
$('#tdClassInfo :checkbox').removeAttr('checked');
$(this).attr('checked', 'checked');
}
});