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>