JavaScript Dom_ Gets the element method _getelementsbyname () Gets a list of nodes of the same name

Source: Internet
Author: User

First, get the node through the label's Name property

1, Getelementsbyname () method gets the node by the Name property of the label, because name has the same, so returns an array of objects htmlcollection (NodeList).

<script type= "Text/javascript" >    function  () {                                 if( Document.getelementsbyname) {               var box = document.getelementsbyname (' text ') [0];            alert (box);             Box.style.color= "Red";                    } Else {            alert ("Browser is incompatible, please replace")        }    }; </script>

2, for not HTML legitimate attributes, then in the JS get compatibility will also exist differences, IE browser support its own legitimate Name property, and illegal will appear incompatible problems.

(IE is not available when it gets the name in the illegal HTML, that is, the Name property itself is not a div attribute, so IE is ignored)

<script type= "Text/javascript" >window.onload=function () {                                 if(document.getelementsbyname) {varinput = document.getelementsbyname (' test ') [0];            alert (input); //Htmlinputelement]alert (input.name);            alert (Input.value); //There is a valid name attribute in input, so IE also supports the}Else{alert ("Browser not compatible, please replace")        }    };</script>

JavaScript Dom_ Gets the element method _getelementsbyname () Gets a list of nodes of the same name

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.