使用jQuery实现多复选框选择和取消选择

Tuesday, June 15, 2010

在很多网站我们都看到有对一个或者所有复选框选择和取消选择

<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
        $("#check_all").live("click",function(event)
        {
            if($("#check_all").hasClass('not_checked'))
            {
                $("#check_all").removeClass('not_checked');
                $(".check-box").attr('checked',true);
            }
            else
            {
                $("#check_all").addClass('not_checked');
                $(".check-box").attr('checked',false);
            }
      });
    </script>
  </head>
  <body>
    <table>
      <tr>
        <td>Select/Deselect</td>
        <td><input type="checkbox" class="check-box not_checked" id="check_all"></td>
      </tr>
      <tr>
        <td>First</td>
        <td><input type="checkbox" class="check-box" id="check_box2"></td>
      </tr>
      <tr>
        <td>Second</td>
        <td><input type="checkbox" class="check-box" id="check_box3"></td>
       </tr>
       <tr>
         <td>Third</td>
         <td><input type="checkbox" class="check-box" id="check_box4"></td>
      </tr>
    </table>
  </body>
</html>

原文: Select/Deselect Multiple CheckBox Using
Jquery

This entry was tagged jQuery

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top