jquery全选全不选反选

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery全选全不选反选相关的知识,希望对你有一定的参考价值。

<!doctype html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>全选、全不选、反选</title>
     <style type="text/css">
         #choose input {
             display: block;
         }
     </style>
     <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
     <script type="text/javascript">
         $(function(){
             var $choose = $("#choose input");
             //全选
             $("#all").click(function(){
                 $choose.each(function(){
                     $(this).prop("checked",true);
                 });
             });
             //全不选
             $("#not").click(function(){
                 $choose.prop("checked",false);
             });
             //反选
             $("#reverse").click(function(){
                 $choose.each(function(){
                     $(this).prop("checked",!$(this).prop("checked"));
                 });
             });
         });
     </script>
 </head>
 <body>
     <div id="box-function">
         <input id="all" type="button" value="全选" />
         <input id="not" type="button" value="全不选" />
         <input id="reverse" type="button" value="反选" />
     </div>
 
     <div id="choose">
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
         <input type="checkbox" />
     </div>
 </body>
 </html>

 

以上是关于jquery全选全不选反选的主要内容,如果未能解决你的问题,请参考以下文章

jquery全选全不选反选

jQuery全选全不选反选

用jQuery实现(全选反选全不选功能)

jQuery实现复选框全选全不选反选问题解析

js 判断 复选框全选全不选反选必选一个

全选全不选反选