jquery Code
$ (function () {
$ (": Checkbox.parentfunc"). Click (function () {
How to get the check box that is clicked
$ (this). Parent (). Parent (). Next (). Find (": CheckBox"). Prop ("Checked", this.checked);
});
$ (": Checkbox:not (. parentfunc)"). Click (function () {
var TD2 = $ (this). Parent (). parent ();
var count1 = Td2.find (": Checked"). Length; The currently selected quantity
var count2 = Td2.find (": CheckBox"). length;//How many check boxes are there in this TD now?
if (count1 = = Count2) {
Td2.prev (). Find (": CheckBox"). Prop ("checked", true);
}
else {
Td2.prev (). Find (": CheckBox"). Prop ("checked", false);
}
})
})
HTML code
<body style= "FONT-SIZE:12PX;" >
<div class= "box" >
Please write JavaScript code to complete the following function requirements: <br/>
1. When the first column is selected, all feature items in the second column of the row are automatically selected. <br/>
2. When the second column feature is not all selected, the first column of the row of the check is also unchecked. <br/>
<span> tip: There are two additional methods that need to be used: parent () and find (). See Help self-study </span>
</div>
<div class= "box" >
<table id= "table1" class= "MyTable" >
<tr>
<td>
<span>
<input type= "checkbox" id= "Chkpromote" class= "Parentfunc"/> Book Management
</span>
</td>
<td>
<span>
<input type= "checkbox" id= "Checkbox1"/> New book Management
</span><span>
<input type= "checkbox" id= "Checkbox2"/> Modify book Management
</span><span>
<input type= "checkbox" id= "Checkbox3"/> Delete book Management
</span>
</td>
</tr>
<tr>
<td>
<span>
<input type= "checkbox" id= "Checkbox4" class= "Parentfunc"/> Member management
</span>
</td>
<td>
<span>
<input type= "checkbox" id= "Checkbox5"/> New member Management
</span><span>
<input type= "checkbox" id= "Checkbox6"/> Modify member Management
</span><span>
<input type= "checkbox" id= "Checkbox7"/> Delete Member management
</span>
</td>
</tr>
<tr>
<td>
<span>
<input type= "checkbox" id= "Checkbox8" class= "Parentfunc"/> System settings
</span>
</td>
<td>
<span>
<input type= "checkbox" id= "Checkbox9"/> Administrator settings
</span><span>
<input type= "checkbox" id= "Checkbox10"/> Role management
</span><span>
<input type= "checkbox" id= "Checkbox11"/> Rights Management
</span>
</td>
</tr>
</table>
</div>
</body>
The
jquery check box is all selected and all check boxes are selected to enable the Select all check box