jquery怎么让八个checkbox只能有一个被选中

 我来答
阿刚炖蛋
2017-03-15 · TA获得超过3004个赞
知道大有可为答主
回答量:1789
采纳率:92%
帮助的人:967万
展开全部

你好!

来个笨方法:

<input type="checkbox" id="t1" name="single" value="1" /><label for="t1" >苹果</label>
<input type="checkbox" id="t2" name="single" value="2" /><label for="t2" >香蕉</label>
<input type="checkbox" id="t3" name="single" value="3" /><label for="t3" >石榴</label>
<input type="checkbox" id="t4" name="single" value="4" /><label for="t4" >西瓜</label>
<input type="checkbox" id="t5" name="single" value="5" /><label for="t5" >橙子</label>
<input type="checkbox" id="t6" name="single" value="6" /><label for="t6" >草莓</label>
<input type="checkbox" id="t7" name="single" value="7" /><label for="t7" >桃子</label>
<input type="checkbox" id="t8" name="single" value="8" /><label for="t8" >蓝莓</label>
<script>
$(document).ready(function(){
  $(":checkbox[name='single']").click(function(){
      $(this).siblings().prop("checked", false);
  });
});
</script>

希望对你有帮助!

哦_廿一
2017-03-15 · TA获得超过431个赞
知道小有建树答主
回答量:273
采纳率:91%
帮助的人:226万
展开全部
<!-- 那你为什么不使用 Radio 呢?radio 只能选择一个 -->
<input type="radio" name="v"> 
<input type="radio" name="v">
<input type="radio" name="v">
<!-- 如果你执意要 checkbox 请继续追问,我给你搞搞 -->
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式