创星网络[分享知识 传递快乐]

标题: jQuery实现CheckBox全选、全不选 [打印本页]

作者: luinstein    时间: 2012-12-13 22:52
标题: jQuery实现CheckBox全选、全不选
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4.     <title>Index</title>

  5.      <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>    <script type="text/javascript">
  6.         $(function() {
  7.             $("#CheckAll").click(function() {
  8.                 var flag = $(this).attr("checked");
  9.                 $("[name=subBox]:checkbox").each(function() {
  10.                     $(this).attr("checked", flag);
  11.                 })
  12.             })
  13.         })
  14.     </script>

  15. </head>
  16. <body>
  17.     <div>
  18.         <input id="CheckAll" type="checkbox" />
  19.         <input name="subBox" type="checkbox" />
  20.         <input name="subBox" type="checkbox" />
  21.         <input name="subBox" type="checkbox" />
  22.         <input name="subBox" type="checkbox" />
  23.     </div>
  24. </body>
  25. </html>
复制代码





欢迎光临 创星网络[分享知识 传递快乐] (http://bbs.cxweb.com.cn/) Powered by Discuz! X3