<table class="table"> <tr> <th>A</th> <th>B</th> <th>C</th> <th>D</th> <th>E</th> </tr> <tr> <td><input class="A" type="checkbox" value="" /></td> <td><input class="B" type="checkbox" value="" /></td> <td><input class="C" type="checkbox" value="" /></td> <td><input class="D" type="checkbox" value="" /></td> <td><input class="E" type="checkbox" value="" /></td> </tr></table>
目的:
在点击td任何地方的时候,checkbox都设置成被选中或取消的状态
但是在点击td选中或者取消checkbox时,如果点击checkbox操作的时候会和td选中 取消冲突,造成checkbox不能选,
js如下:
$(".table").on("click", "tr td", function(){ var checkbox = $(this).find("input[type='checkbox']"); var isChecked = checkbox.is(":checked"); // if (isChecked) { checkbox.removeAttr("checked"); } else { checkbox.attr("checked","true"); } })
怎么才能在td之前 检查点击的是不是checkbox呢?
相关分类