JavaScript Getting Started note: The implementation of the Select all feature

Source: Internet
Author: User

When the page provides a check box, the "Select All" and "deselect All" (or "Uncheck All") buttons are generally available. So how do you do this with JavaScript code? Here's a thought: Using the button's OnClick event, invoking the JavaScript function, and taking the "Select All" and "deselect All" (or "uncheck all") actions based on the parameters passed in, here is the complete code, which is stored in an HTML file to run the demo:


<! DOCTYPE html>
<span style= "White-space:pre" ></span>function selectall (name,tagname,type,scope) */      var selectAll= function (Name,tagname,type,scope) {
<span style= "White-space:pre" ></span>  /* Get all control collections by tag name ("Input") */    elements = document.getElementsByTagName (tagName); var len = Elements.length;for (var i = 0;i<len;i++) {
<span style= "White-space:pre" ></span>/* if the label type is <span style= "font-family:arial, Helvetica, Sans-serif ;" >checkbox and Mark Signature is </span><span style= "font-family:arial, Helvetica, Sans-serif;" >checkbox1,</span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "White-space:pre" ></span> determines how to operate </span><span style= "font-family According to the parameters passed in: Arial, Helvetica, Sans-serif; >*/</span><span style= "font-family:arial, Helvetica, Sans-serif;" ></span>if (elements[i].type==type&&elements[i].name==name&&scope== ' all ') {Elements[i]. Checked=true;} else if (elements[i].type==type&&elements[i].name==name&&scope== ' None ') {elements[i].checked= false;}}} </script>



JavaScript Getting Started note: The implementation of the Select all feature

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.