JS Traversal page control,
Copy Code code 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 code 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 code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<TITLE>JS Traversal Control Value </title>
<mce:script type= "Text/javascript" ><!--
function Submit ()
{
var text=document.getelementsbytagname ("input");
var array= "";
for (Var i=0;i<text.length;i++)
{
if (text[i].type== "Text" | | text[i].type== "checkbox")
{
array+= ",";
Array+=text[i].value;
}
}
Array=array.substring (1,array.length);
alert (Array);
}
--></mce:script>
<body>
<table>
<tr>
<TD style= "width:100px" >
<input id= "Checkbox1" type= "checkbox" Value= "Hugo"/> Hugo </td>
<TD style= "width:100px" >
<input id= "Text1" type= "text" value= "Ws_hgo"/></td>
<TD style= "width:100px" >
<input id= "Button1" type= "button" value= "button" onclick= "Submit (This)"/></td>
</tr>
</table>
</body>
Traverse page Text Control code
Copy Code code as follows:
function texts ()
{
var els= document.getelementsbytagname ("*"); Els get all the controls on the page
var els= document.getelementsbytagname ("INPUT"); The above can also be used to reduce the cycle
var msgs= "";
for (Var i=0;i<els.length;i++)
{
if (Els[i].type = = "Text")
{
Get control ID
Msgs + + els[i].id + ",";
}
}
alert (msgs);
}