jQuery的div选择复选框 [英] jquery select checkbox by div

查看:72
本文介绍了jQuery的div选择复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当有人单击整个div层时,jQuery是否有一种方法可以选中/取消选中复选框.本质上,就像有一个巨大的选择区域.

I'm wondering if there is a way in jQuery to check/uncheck a checkbox when someone clicks an entire div layer. Like having a massive selection area, essentially.

有什么想法吗?

这里是一个示例...我试图使复选框周围的可单击状态几乎可以切换单个复选框.

Here is an example... I am trying to make the around the checkbox clickable to toggle the individual checkbox, pretty much.

<fieldset>
    <div>
        <input type="checkbox" id="Checkbox1" />
    </div>
    Person 1<br />
</fieldset>
<fieldset>
    <div >
        <input type="checkbox" id="Checkbox2" />
    </div>
    Person 2<br />
</fieldset>

推荐答案

也许使用单击的div作为父级.

Perhaps use the clicked div as the parent.

$(function() {
     $('#divId').toggle(
       function(event) {
         $(this).find('input').attr('checked', true);
       },
       function(event) {
         $(this).find('input').attr('checked', false);
       }
     );
 });

这应仅选中单击的#divId中的框.

This should only check the boxes inside the #divId that's clicked.

这篇关于jQuery的div选择复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆