HTML DOM id 屬性
定義和用法
id 屬性設(shè)置或返回 body 元素的 id。
語法
bodyObject.id=id
實(shí)例
下面的例子將展示設(shè)置 <body> 元素的 id 的兩種方法:
<html> <body id="myid"> <script type="text/javascript"> x=document.getElementsByTagName('body')[0]; document.write("Body id: " +x.id
); document.write("<br />"); document.write("An alternate way: "); document.write(document.getElementById('myid').id
); </script> </body> </html>
輸出:
Body id: myid An alternate way: myid