当前位置: 首页 > 网络学院 > 客户端脚本教程 > HTML DOM > HTML DOM id属性
The id property sets or returns the id of the body.
id属性可设置或返回body的id
bodyObject.id=id |
The following example shows two methods on how to get the id of the <body> element:
如何使用两种方法来得到<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> |
Output:
输出
Body id: myid An alternate way: myid |
Return the id of the <body> element
返回<body>元素的id