JS implementation check box operation-------Day41

Source: Internet
Author: User

I do not know why the previous article has been in the audit phase. Is there a word that is sensitive to the crab?

No matter, once again wrote this, also is to deepen the memory.

The first thing to write is the full selection of the check box checkbox used in the table data operation today, and to write the following HTML language first

<table>    <thead>    <tr>    <td><input type= "checkbox" id= "Sall" onchange= " Changeall () "></td>    </tr>    </thead>    <tbody>    <tr>    <td> <input type= "checkbox" Name= "Each" value= "1" ></td>    </tr>    <tr>    <td>< Input type= "checkbox" Name= "Each" value= "2" ></td>    </tr>    <tr>    <td>< Input type= "checkbox" Name= "Each" value= "3" ></td>    </tr>    <tr>    <td>< Input type= "checkbox" Name= "Each" value= "4" ></td>    </tr>    </tbody>    </table >
to write a simpler and more straightforward way to do it after searching the web. It's more than one-fold .

function Changeall () {var Sall=document.getelementbyid ("Sall");//Gets the action object in the title bar var seach=document.getelementsbyname (" Each ");//Gets the object for the content bar for (Var i=0;i<seach.length;i++) {if (sall.checked) {seach[i].checked=true;} Else{seach[i].checked=false;}}}
to analyze the implementation of its method, than the decisive of their own writing is much better, their own at that time took the two methods, but far less than the simple introduction of this molding clear. Their full use ID to operate it is really smelly and long.

There are also more common check boxes for actions on check boxes. For the example above. Let's implement: Onchange= "Change ()"

function change () {var seach=document.getelementsbyname (' each '); for (Var i=0;i<seach.length;i++) {Seach[i]. checked=!seach[i].checked;}}
last. The most common use of a check box is to get the information for a column, which enables the value to be passed. Here we will get the following values:

var seach=document.getelementsbyname ("Each"), for (Var i=0;i<seach.length;i++) {if (seach[i].checked) {alert (seach [I].value];
}}

I don't know what I'm holding on to. It is not as good as the first time to write it again. No matter how much, come on, rookie fly fly ....



JS implementation check box operation-------Day41

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.