The various "Select All" or "cancel" functions of the checkbox are implemented in jquery (pay special attention to the 1.6+ must not use attr to take the property!) With prop! )

Source: Internet
Author: User

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head>    <title></title></Head><Body>    <Scriptsrc= "Http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"type= "Text/javascript">    </Script>    <Script>$ (document). Ready (function () {    varXschk= 'px';//the defined stylevarXschkall= "input[type= ' checkbox '][class= '" +Xschk+ "'] [Name]";//All checkboxes that define this style$ (Xschkall). each (function () {    varname= $( This). Prop ("name"); Name= "input[type= ' checkbox '][class!= '" +Xschk+ "'] [Name= '" +name+ "']";//The sub-checkbox below this all box    $( This). On ('Click', function() {$ (name). Prop ("checked", $( This)[0].checked); })    varXschk= $( This); $ (name). On ('Click', function () {        varIall=$ (name). length;//The number of all checkboxes under this sub-item        varIchk=$ (Name+ ": Checked"). length; //The number of check checkboxes under this sub-item        varisallchecked= true; //whether it is a full selection        if(Iall!=ichk) {isallchecked= false; } $ (Xschk). Prop ("checked", isallchecked);        });});}); </Script>        <legend>Select All</legend>        <inputtype= "checkbox"class= "Xschk"name= "Chk" />Select All<inputtype= "checkbox"name= "Chk" />1<BR/>        <inputtype= "checkbox"name= "Chk" />2<BR/>        <inputtype= "checkbox"name= "Chk" />3<BR/>        <inputtype= "checkbox"name= "Chk" />4<BR/>              <legend>Select All</legend>        <inputtype= "checkbox"class= "Xschk"name= "Chk1" />Select all 2<inputtype= "checkbox"name= "Chk1" /> One<BR/>        <inputtype= "checkbox"name= "Chk1" /> A<BR/>        <inputtype= "checkbox"name= "Chk1" /> -<BR/>        <inputtype= "checkbox"name= "Chk1" /> -<BR/></Body></HTML>

This article is modified in the blog Park A case, now can not find the address of this article, hereby explain!

The various "Select All" or "cancel" functions of the checkbox are implemented in jquery (pay special attention to the 1.6+ must not use attr to take the property!) With prop! )

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.