<div class="codetitle"> <span><a style="CURSOR: pointer" data="70765" class="copybut" id="copybut70765" onclick="doCopy('code70765')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code70765"> <br> <br> <br><title></title> <br><script> <br><br>/* <BR>document节点对象的获取方式: <br><br>*/ <BR>//第一种,通过id获取 <BR>function documentDemo(){ <BR>var tableNode = document.getElementById("tab_id"); <BR>tableNode.style.border = "5px solid #00ff00"; <BR>} <BR>//第二种,通过name属性 <BR>function documentDemo2(){ <BR>var inputNode = document.getElementsByName("txt"); <BR>alert(inputNode.length); <BR>alert(inputNode[0].value); <br><br>} <BR>//第三种,通过标签名 <BR>function documentDemo3(){ <BR>var tdNode = document.getElementsByTagName("td"); <BR>alert(tdNode.length); <BR>for(var x = 0 ; x < tdNode.length;x++){ <BR>alert(tdNode[x].innerText); <BR>} <BR>} <BR></script> <br><br><style type="text/css"> <BR>.onediv{ <BR>width:200px; <BR>height:100px; <BR>border:1px solid #f00; <BR>margin-top:20px; <BR>} <br><br>table ,td{ <BR>border:1px solid #00f; <BR>width:200px; <BR>margin-top:20px; <BR>text-align:center; <BR>} <BR></style> <br><br> <br><br> <br><input type="button" value="document对象演示" onclick="documentDemo3()"><br> <br><div class="onediv"> <br>这是div中的内容 <br> </div> <br><br><input type="txt" name="txt"> <br><input type="txt" name="txt"> <br><br><br><table cellspacing="0" id="tab_id"> <br><tr> <br><td>java</td> <br><td>php</td> <br> </tr> <br><tr> <br><td>.net</td> <br><td>ios</td> <br> </tr> <br> </table> <br><br><span>这是一个span区域</span> <br> <br><a href="#">这是一个超链接</a> <br> <br><br> <br> </div>