checkbox implementation of the full selection of a variety of methods to continuously update [original]_ form effects

Source: Internet
Author: User

Copy Code code as follows:

<script language=javascript>
The first of these methods
function Selectall1 ()
{
var a = document.getElementsByTagName ("input");
if (a[0].checked==true) {
for (var i=0; i<a.length; i++)
if (A[i].type = = "checkbox") a[i].checked = false;
}
Else
{
for (var i=0; i<a.length; i++)
if (A[i].type = = "checkbox") a[i].checked = true;
}
}

The second method

function Selectall2 () {
var tform = document.forms[' Form1 '];
for (Var i=0;i<tform.length;i++)
{
var e = tform.elements[i];
if (E.type = "checkbox")
e.checked =!e.checked;
}
}

The third method, combined with both of these methods
function Selectall3 ()
{
var a = document.getElementsByTagName ("input");
for (var i=0; i<a.length; i++)
if (A[i].type = = "checkbox") a[i].checked =!a[i].checked;
}
Fourth method
function Selectall4 (ID) {//ID Distinguished
var tform=document.forms[' Form1 '];
for (Var i=0;i<tform.length;i++) {
var e=tform.elements[i];
if (e.type== "checkbox" && e.name==id) e.checked=!e.checked;
}
}
Fifth method
function SelectAll (theform,thename) {//theform specified form,thename is the Name property of the checkbox
var tform=document.forms[theform];
document.getElementById ("Thewen"). Value= ' reverse election ';
for (Var i=0;i<tform.length;i++) {
var e=tform.elements[i];
if (e.type== ' checkbox ' && e.name==thename) e.checked=!e.checked;
}
}
</script>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<input type= "checkbox" name= "Sid" Value= "1"/>
<input name= "thes" type= "button" onclick= "Javascript:selectall3 ()" value= "Select All"/>
</form>




<script language=javascript>//First method function Selectall1 () {var a = document.getElementsByTagName ("input") ; if (a[0].checked==true) {for (var i=0 i<a.length; i++) if (A[i].type = "checkbox") a[i].checked = false; else {for (var i=0 i<a.length; i++) if (A[i].type = = "checkbox") a[i].checked = true; }//second method function Selectall2 () {var tform = document.forms[' Form1 ']; for (Var i=0;i<tform.length;i++) {var e = tform.elements[i]; if (E.type = = "checkbox") e.checked =!e.checked; }//Third method, combining the above two methods function Selectall3 () {var a = document.getElementsByTagName ("input"); for (var i=0 i<a.length; i++) if (A[i].type = = "checkbox") a[i].checked =!a[i].checked; The//Fourth method function Selectall4 (ID) {//ID differentiate var tform=document.forms[' Form1 '); for (Var i=0;i<tform.length;i++) {var e=tform.elements[i]; if (e.type== "checkbox" && e.name==id) e.checked=!e.checked; }//Fifth method function Selectall5 (theform,thename) {var tform=document.forms[theform]; document.getElementById ("Thewen"). Value= ' reverse election '; for (Var i=0;i<tform.length;i++) {var e=tform.elements[i]; if (e.type== ' checkbox ' && e.name==thename) e.checked=!e.checked; } </script> <form id= "Form1" Name= "Form1" method= "post" action= "> <input type=" checkbox "Name=" Sid "value=" 1 "/> <input type=" checkbox "name=" Sid "Value=" 2 "/> <input" checkbox "type=" Sid "Name=" 3 "value= Gt <input type= "checkbox" name= "Sid" Value= "4"/> <input name= "thes" button "type=" onclick= 1 () "value=" the first "/> <input name=" thes "type=" button "onclick=" Javascript:selectall2 () "Value=" "The second"/> <i Nput name= "thes" type= "button" onclick= "Javascript:selectall3 ()" value= "third"/> <input name= "thes" type= "button" onclick= "Javascript:selectall4 (' Sid ')" value= "fourth"/> <input name= "thes" type= "button" onclick= "Javascript:selectall5 (' Form1 ', ' Sid ')" value= "fifth kind"/> </form>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

PS: All of the above three methods can achieve effect, but if you want to implement (select All |), you need to add

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.