CheckBox full selection, reverse selection, cancellation

Source: Internet
Author: User

The instance code is as follows:

<! DOCTYPE html>

<meta charset= "UTF-8" >

<title></title>

<body>

<input type= "button" value= "Select All"/>

<input type= "button" value= "Reverse selection"/>

<input type= "button" value= "Cancel"/>


<table border= "1" >

<thead></thead>

<tbody id= "TB1" >

<tr>

<td><input type= "checkbox"/></td>

<td>11</td>

</tr>

<tr>

<td><input type= "checkbox"/></td>

<td>22</td>

</tr>

<tr>

<td><input type= "checkbox"/></td>

<td>33</td>

</tr>


</tbody>


</table>


<script src= "Jquery-3.1.0.min.js" type= "Text/javascript" ></script>

<script type= "Text/javascript" >

function Checkall () {

$ (' #tb1 '). Find (': CheckBox '). attr (' checked ', ' checked ');

$ (' #tb1 '). Find (': CheckBox '). Prop (' checked ', true);

attr and prop differences, attr is set for all label properties, prop is a special property setting for check and Radio checkboxes


}


function Checkreverse () {

Find, if selected, cancel; unchecked, select;

$ (' #tb1 '). Find (': CheckBox '). each (function () {

$ (this) each check box

$ (this). Prop (), if selected, true, otherwise false

attr If selected; checked,checked=checked

if ($ (this). Prop (' checked ')) {


$ (this). Prop (' checked ', false);

}else{


$ (this). Prop (' checked ', true);

}


});


}

function Checkcancel () {

$ (' #tb1 '). Find (': CheckBox '). Removeattr (' checked ');

$ (' #tb1 '). Find (': CheckBox '). Prop (' checked ', false);


}

</script>


</body>


This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1847218

CheckBox full selection, reverse selection, cancellation

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.