如何用jquery实现checkbox点选一个选中其他,取消一个取消其他

 我来答
ygh31500
推荐于2017-11-26 · TA获得超过158个赞
知道答主
回答量:118
采纳率:100%
帮助的人:124万
展开全部
<script language="javascript">
<!-- 
function checkBox(obj) {
// 只有当选中的时候才会去掉其他已经勾选的checkbox,所以这里只判断选中的情况
    if (obj.is(":checked")) {
         // 先把所有的checkbox 都设置为不选种
        $('input.mybox').prop('checked', false);
        // 把自己设置为选中
        obj.prop('checked',true);
    }
}
//-->
</script>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
<input type="checkbox" class="mybox" onclick="checkBox($(this));"/>
百度网友c07a0afe31
2014-11-18 · 超过21用户采纳过TA的回答
知道答主
回答量:53
采纳率:0%
帮助的人:39.4万
展开全部
each() 所有的checkbox 然后判断
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式