Home  >  Article  >  Web Front-end  >  Detailed analysis of javascript traversal control instances_javascript skills

Detailed analysis of javascript traversal control instances_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:04:331255browse

js traverses page controls,

Copy code The code is as follows:

var inputArr = document.forms[0];
for( var i = 0; i < inputArr.length; i ) {
if( inputArr[i].type.toUpperCase() == "BUTTON" ) {
inputArr[i].disabled= "disabled";
}else if( inputArr[i].type.toUpperCase() == "FILE" ){
inputArr[i].readonly=true;
}
}

Another method:

Copy code The code is as follows:

var Elements = document.getElementsByTagName_r("*");
var msgs;
var i;
for ( i in Elements ) {
if ( Elements[i].type == "text" ) {
alert(Elements[i]. value);
}
}

JS traversal control value

Copy code The code is as follows:


JS traversal control value



"width: 100px">
: 100px">
 🎜>                                                                                                                          table>






Traverse the page text control code


Copy code

The code is as follows:
Function Texts ()
{
// var Els = Document.GetelementsBytagname ("*"); // Els get all the controls of the page
Var Els = ("Input "); //The above is also possible, which can reduce loops
                                                                                                                             els[i].type == "text" )
                                                                                                                                                                                                                                                                                      alert(msgs);
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn