jQuery中获取checkbox选中项等操作及注意事项(3)


            //反选
            $('#fanxuan').click(function () {
                $("input[name='abc']").each(function () {
                    if ($(this).attr("checked")) {
                        $(this).removeAttr("checked");
                    } else {
                        $(this).attr("checked", 'true');
                    }
                });
            });
        });

</script>
</head>
<body>
    <form runat="server">
        <div>
            <input type="checkbox" value="一年级" checked="checked" /><label for="in1">一年级</label>
            <input type="checkbox" value="二年级" /><label for="in2">二年级</label>
            <input type="checkbox" value="三年级" /><label for="in3">三年级</label>
            <input type="checkbox" value="四年级" /><label for="in4">四年级</label>
            <input type="checkbox" value="五年级" /><label for="in5">五年级</label>
            <input type="checkbox" value="六年级" /><label for="in6">六年级</label>
            <input type="checkbox" value="七年级" /><label for="in7">七年级</label>
            <input type="checkbox" value="八年级" /><label for="in8">八年级</label>
        </div>
        <br />
        <input type="button" value="获取选中项(FF和chrome下无效)" />
        <input type="button" value="全选/取消全选" />
        <input type="button" value="反选" />
        <input type="button" value="获取选中项" />
       <br />
        选中项: <div>

</div>
    </form>
</body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdwxxj.html