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