The full selection of the jquery checkbox is not selected and all check boxes are selected to enable the Select all check box

Source: Internet
Author: User
Tags prev

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

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.