1. When a select checkbox is selected, all sub-checkboxes are selected. Conversely, all do not choose
2. In the Sub-checkbox, deselect the Select CheckBox as long as there is no selection
3. If the number of sub-checkboxes is the same as the number of sub-checkboxes selected, the Select checkbox is selected
[JavaScript]View PlainCopy
- check box events
- Select All, Cancel all selected events
- function SelectAll () {
- if ($ ("#SelectAll"). attr ("checked")) {
- $ ("input[name= ' Subcheck ')"). attr ("Checked", true);
- } Else {
- $ (": CheckBox"). attr ("checked", false);
- }
- }
- Sub-check box events
- function Setselectall () {
- //When a child check box is not selected, SelectAll uncheck
- if (!$ ("#subcheck"). Checked) {
- $ ("#SelectAll"). attr ("Checked", false);
- }
- var chsub = $ ("input[type= ' checkbox '][name= ' Subcheck ']"). Length; //Get the number of Subcheck
- var checkedsub = $ ("input[type= ' checkbox '][name= ' Subcheck ']:checked"). Length; //Get the number of selected Subcheck
- if (checkedsub = = chsub) {
- $ ("#SelectAll"). attr ("Checked", true);
- } else{
- $ ("#SelectAll"). attr ("checked", false);}
- }
The ID of the Select checkbox is SelectAll, and the name of the sub-checkbox is Subcheck.
The JSP page code is as follows:
[HTML]View PlainCopy
- <input type="checkbox" id="SelectAll" value="Select All" onclick="SelectAll ();" />
- <input type="checkbox" name="subcheck[]" value="1" onclick="Setselectall ();" />
- <input type="checkbox" Name="subcheck[]" value="2" onclick=" Setselectall (); " />
- <input type="checkbox" Name="subcheck[]" value="3" onclick="Setselectall ();" />
- <input type="checkbox" Name="subcheck[]" value="4" onclick=" Setselectall (); " />
jquery implements a checkbox to select all, reverse.