According to everyone's opinions on the procedures in some of the bad writing, but also the level of my limited, there are a variety of places to consider.
At the end of the article I raised a question, to write a general method to call, so I have the present article, the evening home, I wrote the effect
The following examples can be used to discuss learning, if you feel good can also be applied directly to the project.
Development process: To achieve universal will solve 2 problems, how to group, how to determine which checkbox in the group for all election, I think, think by name Group can,
Use class to determine whether a checkbox group that requires a full selection. Find all classes First and then find the Name property, and you can find the other child checkbox based on the Name property, as long as you find the element, you can do it.
Here is my implementation of JS, save for Xs_checkbox_all.js
Author: frivolous scholar//Blog address: http ://www.cnblogs.com/xiaoshuai1992//CREATE:2014/1/15//function: To implement the smart selection//Usage of a checkbox: Refer to jquery, set the name of the checkbox group to select All, All selected checkbox set class to the following variable Xschk//********************************************************************************* $ (document). Ready (function () { var xschk = "Xschk";//Defined style var xschkall = "Input[type= ' checkbox '][class= '" + xschk + "'][name]";//All checkbox $ (xschkall) that define this style. each ( function () { var name = $ (this). attr ("name"); name = "input[type= ' checkbox '][class!= '" + xschk + "'][name= '" + name + "']";//the Child checkbox under this Full selection box & nbsp; $ (this). Click (function () {
$ (name). attr ("Checked", $ (this) [0].checked); }) var xschk = $ (this); $ (name). Click (function () { var iall = $ (name). length; The number of all the checkbox under this subproject var ichk = $ (name + ": Checked "). Length; The number of all checkboxes under this subproject var isallchecked = true; Whether it is a full selection if (Iall!= ichk) {
isallchecked = false; }
$ (XSCHK). attr ("Checked", isallchecked);
});
}); });
Page Use
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
">