luinstein 发表于 2012-12-13 22:52:49

jQuery实现CheckBox全选、全不选

<!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 runat="server">
    <title>Index</title>

   <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>    <script type="text/javascript">
      $(function() {
            $("#CheckAll").click(function() {
                var flag = $(this).attr("checked");
                $(":checkbox").each(function() {
                  $(this).attr("checked", flag);
                })
            })
      })
    </script>

</head>
<body>
    <div>
      <input id="CheckAll" type="checkbox" />
      <input name="subBox" type="checkbox" />
      <input name="subBox" type="checkbox" />
      <input name="subBox" type="checkbox" />
      <input name="subBox" type="checkbox" />
    </div>
</body>
</html>
页: [1]
查看完整版本: jQuery实现CheckBox全选、全不选