<!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! )