jQuery如何实现table中两列CheckBox只能选中一个方法
来源:动视网
责编:小OO
时间:2020-11-27 20:08:44
jQuery如何实现table中两列CheckBox只能选中一个方法
//html;<;table id=";unit";>;<;tr>;<;th>;选项一<;/th>;<;th>;选项二<;/th>;<;th>;姓名<;/th>;<;/tr>;<;tr>;<;td>;<;input type=";checkbox";/>;<;/td>;<;td>;<;input type=";checkbox";/>;<;/td>;<;td>;小红<;/td>;<;/tr>;<;tr>;<;td>;<;input type=";/>。
导读//html;<;table id=";unit";>;<;tr>;<;th>;选项一<;/th>;<;th>;选项二<;/th>;<;th>;姓名<;/th>;<;/tr>;<;tr>;<;td>;<;input type=";checkbox";/>;<;/td>;<;td>;<;input type=";checkbox";/>;<;/td>;<;td>;小红<;/td>;<;/tr>;<;tr>;<;td>;<;input type=";/>。
本文主要为大家带来一篇jQuery实现table中两列CheckBox只能选中一个的示例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。
//html
<table id="unit">
<tr>
<th>选项一</th>
<th>选项二</th>
<th>姓名</th>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td>小红</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
<td>小明</td>
</tr>
</table>
//jQuery
<script type="text/javascript">
$(function(){
$("#unit tr").click(function () {
$(this).siblings().find("input[type='checkbox']").removeAttr("checked");
});
})
</script>
//效果图,暂时上传不了动态的,亲测有用的

jQuery如何实现table中两列CheckBox只能选中一个方法
//html;<;table id=";unit";>;<;tr>;<;th>;选项一<;/th>;<;th>;选项二<;/th>;<;th>;姓名<;/th>;<;/tr>;<;tr>;<;td>;<;input type=";checkbox";/>;<;/td>;<;td>;<;input type=";checkbox";/>;<;/td>;<;td>;小红<;/td>;<;/tr>;<;tr>;<;td>;<;input type=";/>。