美文网首页
用jQuery实现全选和取消全选

用jQuery实现全选和取消全选

作者: 欣_m | 来源:发表于2019-08-13 21:05 被阅读0次

全选 取消全选

checkAll是全选按钮的id

check是每个checkbox的class名

prop()方法可以用于设置属性,也可以用于判断是否存在某个属性

each()方法遍历每个class名为check的元素


 $("#checkAll").on("click", function () {

        if ($("#checkAll").prop("checked")) {

            $(".check").each(function () {

                $(this).prop("checked", true);

            })

            var arr = "";

            var name = $(".name").text();

            arr += name;

            console.log("姓名:" + arr);

        } else {

            $(".check").each(function () {

                $(this).prop("checked", false);

            })

        }

    })

相关文章

网友评论

      本文标题:用jQuery实现全选和取消全选

      本文链接:https://www.haomeiwen.com/subject/axrijctx.html