关于jq操作table下多个type=radio的input的选中

时间:2023-03-09 13:26:33
关于jq操作table下多个type=radio的input的选中

假如有2个table:

<table id="table1" border="0">
<tr>
<td><input id="rdu_0" type="radio" name="rdu" value="1" checked="checked" /><label for="rdu_0">第一个</label></td>
</tr><tr>
<td><input id="rdu_1" type="radio" name="rdu" value="2" /><label for="rdu_1">第2个</label></td>
</tr><tr>
<td><input id="rdu_2" type="radio" name="rdu" value="3" /><label for="rdu_2">第3个</label></td>
</tr>
</table>

<table id="table2" border="0">
<tr>
<td><input id="rrr_0" type="radio" name="rrr" value="1" checked="checked" /><label for="rrr_0">第一个</label></td>
</tr><tr>
<td><input id="rrr_1" type="radio" name="rrr" value="2" /><label for="rrr_1">第2个</label></td>
</tr><tr>
<td><input id="rrr_2" type="radio" name="rrr" value="3" /><label for="rrr_2">第3个</label></td>
</tr>
</table>

在第一个table中的某个input选中之后,第二个table的所有input全部未选中

<script type="text/javascript">
$("#table1").find("input").click(function(){ //给table下的所有input加click事件
$("#table2").find("input").each(function(){//遍历所有table2下的input

$(this).attr("checked","");
})

})
</script>