Jquery/javascript for all-in-all selection

Source: Internet
Author: User

123<meta charset= "Utf-8" >4<title>checkbox's Exercises </title>5<style type= "Text/css" >6*{margin:0px;padding:0px;}7table{width:100%;text-Align:center;} 8</style>9 Ten<script src= "Jquery.js" ></script> One<script language= "JavaScript" > A$(function(){ -         //add an event to a Select all check box -$ ("#all"). Click (function(){ the             //This check box is all selected -             varuserids= This. Checked; -             //Get name=box check box to traverse output check box -$ ("Input[name=box]"). each (function(){ +                  This. checked=UserIDs; -             }); +         }); A          at         //bind the Name=box to the check box -$ ("Input[name=box]"). Click (function(){ -             //Get checked check box length -             varlength=$ ("input[name=box]:checked"). length; -             //unselected length -             varlen=$ ("Input[name=box")). length; in             if(length==Len) { -$ ("#all"). Get (0). checked=true; to}Else{ +$ ("#all"). Get (0). checked=false; -             } the         }); *     }); $     Panax Notoginseng      -</script> the +<body> A<div> the<form action= "" method= "POST" > +<table border= "1px" > -<tr> $<th> $<input type= "checkbox" id= "All"/> Select all -</th> -<th> User Number </th> the<th> User Account </th> -<th> User name </th>Wuyi<th> User Sex </th> the<th> User Age </th> -<th> Home Address </th> Wu</tr> -<tr> About<td><input type= "Checkbox" name= "box" value= "10010"/></td> $<td>10010</td> -<td>root</td> -<td> Heart Grow fonder </td> -<td> Men </td> A<td>22</td> +<td> Henan </td> the</tr> -<tr> $<td><input type= "Checkbox" name= "box" value= "10011"/></td> the<td>10011</td> the<td>root</td> the<td> Xiao Li </td> the<td> Men </td> -<td>23</td> in<td> Henan </td> the</tr> the<tr> About<td><input type= "Checkbox" name= "box" value= "10012"/></td> the<td>10012</td> the<td>root</td> the<td> Xiao Zhao </td> +<td> Men </td> -<td>21</td> the<td> Henan </td>Bayi</tr> the<tr> the<td><input type= "Checkbox" name= "box" value= "10013"/></td> -<td>10013</td> -<td>root</td> the<td> Small Week </td> the<td> Men </td> the<td>25</td> the<td> Henan </td> -</tr> the<tr> the<td><input type= "Checkbox" name= "box" value= "10014"/></td> the<td>10014</td>94<td>root</td> the<td> Xiao Wu </td> the<td> Men </td> the<td>20</td>98<td> Henan </td> About</tr> -</table>101         102</form>103</div>104</body> the

123<meta charset= "Utf-8" >4<title>checkbox's Exercises </title>5<style type= "Text/css" >6*{margin:0px;padding:0px;}7table{width:100%;text-Align:center;}8     9</style>Ten<script language= "JavaScript" > One     functionCheckall (obj) { A         //alert (obj.checked); -         //Get the check box for Name=box -         varUserids=document.getelementsbyname ("box"); the         //alert (userids.length); -          for(vari=0;i<userids.length;i++){ -Userids[i].checked=obj.checked; -         } +     } -  +     functionSelectAll () { A         //Get the check box for Name=box at         varUserids=document.getelementsbyname ("box"); -         varCount=0; -         //Iterate through all the check boxes -          for(vari=0;i<userids.length;i++){ -             if(userids[i].checked) { -count++; in             } -         } to         //Select the number of check boxes = = Gets the number of check boxes +         if(count==userids.length) { -         //the set ID for all check box is selected thedocument.getElementById ("All"). checked=true; *}Else{ $         //the set ID of all check box is uncheckedPanax Notoginsengdocument.getElementById ("All"). checked=false; -         } the          +     } A</script> the +<body> -<div> $<form action= "" method= "POST" > $<table border= "1px" > -<tr> -<th> the<input type= "Checkbox" onclick= "Checkall (This)" id= "All"/> Select all -</th>Wuyi<th> User Number </th> the<th> User Account </th> -<th> User name </th> Wu<th> User Sex </th> -<th> User Age </th> About<th> Home Address </th> $</tr> -<tr> -<td><input type= "Checkbox" name= "box" onclick= "SelectAll ()" value= "10010"/></td> -<td>10010</td> A<td>root</td> +<td> Heart Grow fonder </td> the<td> Men </td> -<td>22</td> $<td> Henan </td> the</tr> the<tr> the<td><input type= "Checkbox" name= "box" onclick= "SelectAll ()" value= "10011"/></td> the<td>10011</td> -<td>root</td> in<td> Xiao Li </td> the<td> Men </td> the<td>23</td> About<td> Henan </td> the</tr> the<tr> the<td><input type= "Checkbox" name= "box" onclick= "SelectAll ()" value= "10012"/></td> +<td>10012</td> -<td>root</td> the<td> Xiao Zhao </td>Bayi<td> Men </td> the<td>21</td> the<td> Henan </td> -</tr> -<tr> the<td><input type= "Checkbox" name= "box" onclick= "SelectAll ()" value= "10013"/></td> the<td>10013</td> the<td>root</td> the<td> Small Week </td> -<td> Men </td> the<td>25</td> the<td> Henan </td> the</tr>94<tr> the<td><input type= "Checkbox" name= "box" onclick= "SelectAll ()" value= "10014"/></td> the<td>10014</td> the<td>root</td>98<td> Xiao Wu </td> About<td> Men </td> -<td>20</td>101<td> Henan </td>102</tr>103</table>104          the</form>106</div>107</body>108

Jquery/javascript for all-in-all selection

Related Article

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.