JavaScript traversal Control instance detailed parsing _javascript tips

Source: Internet
Author: User

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" >
&LT;TITLE&GT;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>
&LT;TD style= "width:100px" >
<input id= "Checkbox1" type= "checkbox" Value= "Hugo"/> Hugo </td>
&LT;TD style= "width:100px" >
<input id= "Text1" type= "text" value= "Ws_hgo"/></td>
&LT;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);
}

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.