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 any word is sensitive to the crab?

Anyway, re-write this, it is also a deep 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 more simple and straightforward way to read from the web, more than one-fold better than your own.

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, I took two methods at that time, but far less than the introduction of this molding clear, their full use of ID to operate really smelly and long.

There is a more common check box for the check box, and for the example above, let's do the following: onchange= "Change ()"

function change () {var seach=document.getelementsbyname (' each '); for (Var i=0;i<seach.length;i++) {Seach[i]. checked=!seach[i].checked;}}
Finally, the most commonly used check box is to get a column of information, so as to achieve the value, here we get the following value:

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

Do not know what they insist on what, so rewrite it again, the effect, it is not the first time to come so good, no matter how much, refueling bar, rookie Fei Fei Fei ....



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.