JS traverse 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]. Rreamonly = 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">>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<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] .epe == "Checkbox")
{{
Array+= ",";;;
Array+= text [i]. Value;
}
}
Array = array.substring (1, array.length);
alert (array);
}
// -> </mce: script>
</head>
<body>
<Table>
<tr>
<TD>
<input ID = "Checkbox1" Type = "Checkbox" Value = "Hu Guo" /> Hu Guo < /td>
<TD>
<input ID = "Text1" Type = "Text" Value = "ws_hgo" /> < /td>
<TD>
<input ID = "Button1" Type = "Button" Value = "Button" Onclight = "Submit (this)" /> < /td>
</tr>
</table>
</body>
</html>
Traversing page Text control code
Copy code code as follows:
Function Texts ()
{{
// var els = document.GetelementsBytagname ("*"); // Els get all controls on the page
var els = document.GetelementsBytagname ("input"); // also above, so as to reduce the cycle
var msgs = "";
for (var I = 0; I <els.Length; i ++)
{{
if (els [i] .Type == "Text")
{{
// Get the control ID
msgs + = els [i] .id + ",";;
}
}
alert (msgs);
}