JS Beginner-Enable CheckBox Select All function

Source: Internet
Author: User
Tags define function

The layout is as follows:

<p ><input type= "checkbox" id= "Che1"/> Select all </p>
<DivID= "Div1"> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/></Div>

JavaScript is as follows:

<script type= "Text/javascript" >window.onload=function() {Xuanzhe (); }    functionXuanzhe ()//define function {varOche1=document.getelementbyid (' Che1 ');//Get Che1varOdiv1=document.getelementbyid (' Div1 '). getElementsByTagName (' input '));//Get all input Oche1.onclick in Div=function()//define the CHE1 mouse click event { for(vari=0;i<odiv1.length;i++)                        {                            if(che1.checked==true) {odiv1[i].checked=true; }                            Else{odiv1[i].checked=false;    }                        }                                                    }; }</script>

Can realize checkbox Select All Function! This feature is widely used in Web pages!

JS Beginner-Enable CheckBox Select All function

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.