Home > Web Front-end > JS Tutorial > Based on jQuery, implement the check box selection all, unselect all, and inverse selection function_jquery

Based on jQuery, implement the check box selection all, unselect all, and inverse selection function_jquery

WBOY
Release: 2016-05-16 16:30:31
Original
1454 people have browsed it

This code is selected from many jQuery check box function codes. The code used in my project is shared with everyone here.

jQuery code:

Copy code The code is as follows:

         $(function(){
                  $("#checkedAll").click(function(){
                                                       $('[name=items]:checkbox').attr('checked',true);
              });
                 $("#checkedNo").click(function(){
                                                           $('[name=items]:checkbox').attr('checked',false);
              });
                $("#checkedRev").click(function(){
                        $('[name=items]:checkbox').each(function(){
//$(this).attr('checked',!$(this).attr('checked'));
This.checked = !this.checked;
                 });
              });
                 $("#send").click(function(){
Var Str = "What you choose is: n";
                      $('[name=items]:checkbox:checked').each(function(){
                       str = $(this).val() "rn";
                });
alert(str);
              });
        });

HTML code:

Copy code The code is as follows:

What is your favorite sport?

football
basketball
Badminton
table tennis





Friends, is it very convenient to use? This is what I have chosen. I hope it can be helpful to everyone.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template