保捱科技网
您的当前位置:首页table中两列CheckBox只能选中一个的jQuery代码

table中两列CheckBox只能选中一个的jQuery代码

来源:保捱科技网
 本文主要为大家带来一篇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>

//效果图,暂时上传不了动态的,亲测有用的

显示全文