<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>function documentDemo3(){ <BR>var tdNode = document.getElementsByTagName("td"); <BR>alert(tdument.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-toptop :20px; <BR>} <BR><br>table ,td{ <br>border:1px solid #00f; <BR>width:200px; <BR>margin-top:20px; <>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><br> </div>