Jquery 复选框全选与反选点击执行一次然后失效解决方案

2018-12-06  本文已影响8人  青木川_

// 使用attr只能执行一次

function selectAll(o) {

            if (o.checked) {

                $(".chkCss").attr("checked", true);

            } else {

                $(".chkCss").attr("checked", false);

            }

        }

// 使用prop则完美实现全选和反选

$('#all').on('click', function () {

                if (this.checked) {

                    //$("input[name='check']").attr('checked', true);

                    $("input[name='check']").prop('checked', true);

                } else {

                    $("input[name='check']").prop('checked', false);

                }

            });

上一篇 下一篇

猜你喜欢

热点阅读