jquery全选和反选
更新:HHH   时间:2023-1-7


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts\jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#selectAll").click(function () {
                $("#playList :checkbox").attr("checked", true);
            });
            $("#unSelect").click(function () {
                $("#playList :checkbox").attr("checked", false);
            });
            $("#reverse").click(function () {
                $("#playList :checkbox").each(function () {
                    $(this).attr("checked", !$(this).attr("checked"));
                });
            });
        })
    </script>
</head>
<body>
    <h4>你喜欢的咖啡是?</h4>
    <div id="playList">
    <input type="checkbox"  value="蓝山咖啡"  />蓝山咖啡<br/>
    <input type="checkbox" value="拿铁" />拿铁<br/>
    <input type="checkbox" value="卡布奇诺" />卡布奇诺<br/>
    <input type="checkbox" value="终南山" />终南山<br/>
    <input type="checkbox" value="黑豆" />黑豆<br/>
    </div>
    <input type="button"  id="selectAll" value="都喜欢" />
    <input type="button" id="unSelect" value="都不喜欢"/>
    <input type="button" id="reverse" value="反选"/>
</body>
</html>


返回web开发教程...