Sample acquisition method for document node object introduction to _javascript Tips

Source: Internet
Author: User
Copy Code code as follows:

<title></title>
<script>

/*
How the Document node object is obtained:

*/
The first type is obtained by ID
function Documentdemo () {
var tablenode = document.getElementById ("tab_id");
TableNode.style.border = "5px solid #00ff00";
}
The second, through the Name property
function DocumentDemo2 () {
var inputnode = document.getelementsbyname ("txt");
alert (inputnode.length);
alert (Inputnode[0].value);

}
Third, by sign
function DocumentDemo3 () {
var tdnode = document.getElementsByTagName ("TD");
alert (tdnode.length);
for (var x = 0; x < tdnode.length;x++) {
alert (Tdnode[x].innertext);
}
}
</script>

<style type= "Text/css" >
. onediv{
width:200px;
height:100px;
border:1px solid #f00;
margin-top:20px;
}

Table, td{
border:1px solid #00f;
width:200px;
margin-top:20px;
Text-align:center;
}
</style>


<body>
<input type= "button" value= "Document object Demo" onclick= "DocumentDemo3 ()" ><br/>
<div class= "Onediv" >
This is the content of the DIV
</div>

<input type= "txt" name= "TXT" >
<input type= "txt" name= "TXT" >


<table cellspacing= "0" id= "tab_id" >
<tr>
<td>java</td>
<td>php</td>
</tr>
<tr>
<td>.net</td>
<td>ios</td>
</tr>
</table>

<span> This is a span area </span> <br/>
<a href= "#" > This is a hyperlink </a>
<body>

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.