用jQuery实现(全选、反选、全不选功能)

在jQuery选择器的基础下我们实现一个全选,反选,全不选功能!

    <script type="text/javascript">
        $(function ()
        {
            //全选
            $("#selectAll").click(function () {
                //attr在HTML推荐非固有(用户自定义)属性是使用
                //prop在HTMl元素固有属性的时候使用
                $("input[name='gx']").each(function () {//input[name='gx']属性过滤选择器
                    $(this).prop("checked", true);
                })
            });
            //全不选
            $("#selectNotAll").click(function () {
                $("input[name='gx']").each(function () {
                    $(this).prop("checked", false);
                })
            });
            //反选
            $("#selectRevorse").click(function ()
            {
                $("input[name='gx']").each(function ()
                {
                    $(this).prop("checked",!this["checked"]);
                });
            })
        })
    </script>

猜你喜欢

转载自www.cnblogs.com/qinwenfeng/p/9497116.html