如何在Jquery中检查多个复选框? [英] How Can I Check Multiple Check Boxes in Jquery?

查看:87
本文介绍了如何在Jquery中检查多个复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,每行开头都有一个复选框。每个复选框的ID为#tablecheckbox。表标题行有一个检查图标,应该检查表中的所有框。我怎么能这样做与Jquery?提前感谢!

I have a table with a checkbox at the start of each row. Each Checkbox has the ID of #tablecheckbox. The table header row has a check icon which should check all boxed in the table. How can I do this with Jquery? Thanks in advance!

推荐答案

这里head_checkbox是顶部标题的ID,人类是所有行复选框

Here head_checkbox is id of top header and person class is all row checkbox

 $('#head_checkbox').on('change', function () {
            if ($(this).is(':checked')) {
                $('.person').attr('checked', true);
            } else {
                $('.person').attr('checked', false);
            }
        });

        $('.person').click(function () {
            var total_length = $('.person').length;
            var total_checked_length = $('.person:checked').length;

            if (total_length == total_checked_length) {
                $('#head_checkbox').attr('checked', true);
            } else {
                $('#head_checkbox').attr('checked', false);
            }
        });

这篇关于如何在Jquery中检查多个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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