Comprehensive JScheckbox selection, cancellation of all selections, and deletion of function code _ javascript skills

Source: Internet
Author: User
Today, the code for controlling all checkbox selection, canceling all selection, and deleting functions in JS is pasted .. See the following two implementation methods:
JS checkbox Method 1:

The Code is as follows:


Function checkAll ()
{
Var code_Values = document. all ['Code _ value'];
If (code_Values.length ){
For (var I = 0; I {
Code_Values [I]. checked = true;
}
} Else {
Code_Values.checked = true;
}
}
Function uncheckAll ()
{
Var code_Values = document. all ['Code _ value'];
If (code_Values.length ){
For (var I = 0; I {
Code_Values [I]. checked = false;
}
} Else {
Code_Values.checked = false;
}
}
Function multipleDelete ()
{
Var num = 0;
Var code_Values = document. all ['Code _ value'];
If (code_Values.length ){
For (var I = 0; I {
If (code_Values [I]. checked = true)
{
Num ++;
}
}
} Else {
If (code_Values.checked = true ){
Num ++;
}
}
If (num = 0 ){
Alert ('Please select delete item ');
}
If (num> 0 ){
Document. BuCodeSearch. action = '<% = EusUtil. getPage ("lookup. generic. bucode. delete. s") %> ';
Document. BuCodeSearch. submit ();
}
}
Script


JS checkbox Method 2:

The Code is as follows:


Function checkAll ()
{
Var code_Values = document. getElementsByTagName ("input ");
For (I = 0; I <code_Values.length; I ++ ){
If (code_Values [I]. type = "checkbox ")
{
Code_Values [I]. checked = true;
}
}
}
Function uncheckAll ()
{
Var code_Values = document. getElementsByTagName ("input ");
For (I = 0; I <code_Values.length; I ++ ){
If (code_Values [I]. type = "checkbox ")
{
Code_Values [I]. checked = false;
}
}
}
Function multipleDelete ()
{
If (document. BuCodeSearch. elements ["code_Value"])
{
Var num = 0;
Var fm = document. BuCodeSearch;
If (document. BuCodeSearch. elements ["code_Value"])
{
Var elm = document. BuCodeSearch. elements ["code_Value"];
Var ename = "code_Value ";
If (elm. length ){
Var len = fm. elements [ename]. length;
For (var I = 0; I <len; I ++ ){
Var e = fm. elements [ename] [I];
If (e. checked = true ){
Num ++;
}
}
} Else {
If (elm. checked = true ){
Num ++;
}
}
If (num> 0)
{
Document. BuCodeSearch. action = '<% = EusUtil. getPage ("lookup. generic. bucode. delete. s") %> ';
Document. BuCodeSearch. submit ();
}
}
}
}


Code_Value is the name of the checkbox form, and BuCodeSearch is the form name.

The Code is as follows:


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.