Universal Writing of CheckBox full selection/non-selection by jquery

Source: Internet
Author: User

  This article is mainly on the jquery implementation of checkbox Select/all the general wording of the introduction, the need for friends can come to the reference, I hope to help you.

  Code as follows: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > <html> <head>     <script type= " Text/javascript "src=" Http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js "></script>     <script type= "Text/javascript" >        //name is an HTML form dedicated to distinguishing between groups of chechbox properties, do not use IDs (must be unique) or User other properties         function getValues () {            var AV = Getcheckboxval UEs ("a");             var BV = getcheckboxvalues ("B");             var CV = getcheckboxvalues ("C");               var result = "A group of selected values:" + (av== ""?) "No value selected": AV) + "n" +                 "Group B selected:" + (BV = = ""?) No value selected ": BV" + "n" +                 "Group C selected:" + (CV = = ""?) No value selected: CV);           &NBSp   alert (result);        }           function getcheckboxvalues (name) {      & nbsp     Return $ (": Checkbox[name=" +name+ "]:checked"). Map (function () {            & nbsp     return $ (this). Val ();             }). Get (). Join (",");        }           function Chkall (obj) {            var name = $ (obj). attr ("name");            //Maybe you think I write too complex, but the jquery version is so numerous that it's always good to learn something.           &NBSP ; 1. jquery 1.6            //$ (": checkbox[name=" + name.substring (0, 1) + "]"). Prop ("Checked" , $ (obj). Prop ("checked"));            //2. jquery 1.6            //$ (": checkbox[name=" + name.substring (0, 1) + "]"). attr ("Checked" , $ (obj).attr ("checked"));            //3. General writing             $ (": checkbox[name=" + name.substring (0, 1) + "]"). each (function () {                this.checked = obj.checked;            });        }     </script> </head> <body>     <div >   & nbsp     <span> 1th Group (a): <input type= "checkbox" Name= "Aall" onclick= "Chkall (This)"/> Select all/All options </span >         <input type= "checkbox" Name= "a" value= "A1" checked= "Checked"/>a1     &NB Sp   <input type= "checkbox" Name= "a" value= "A2" checked= "checked"  />a2         <INPU T type= "checkbox" Name= "a" value= "A3"/>a3         <input type= "checkbox" Name= "a" value= "A4"/& Gt;a4<br/>           <span> 2nd (b): <inPut type= "checkbox" Name= "BAll" onclick= "Chkall (This)"/> Select All/Select All </span>         <input type= "checkbox" Name= "B" value= "B1"/>b1         <input type= "checkbox" Name= "B" value= "B2" Chec Ked= "Checked"/>b2         <input type= "checkbox" Name= "B" value= "B3" checked= "checked"  / >B3         <input type= "checkbox" Name= "B" value= "B4"/>b4<br/>           <span> 3rd Group (c): <input type= "checkbox" Name= "Call" onclick= "Chkall (This)"/> Select all/All </span >         <input type= "checkbox" Name= "C" value= "C1"/>C1         <INP UT type= "checkbox" Name= "C" value= "C2"/>c2         <input type= "checkbox" Name= "C" Value= "C3" C Hecked= "Checked"/>c3         <input type= "checkbox" Name= "C" value= "C4" checked= "Checked" &nbs p;/>c4<br/>     &NBsp     <br/>         <input type= "button" value= "Find selected values for each group" onclick= "GetValues ()"/&G T     </div> </body> </html>    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.