HTML DOM id 属性

定义和用法

id 属性可设置或返回 iframe 的 id。

语法

  1. iframeObject.id=id

实例

本例展示了两种返回 iframe 的 id 的方法:

  1. <html>
  2. <body>
  3.  
  4. <iframe src="frame_a.htm" id="frame1"></iframe>
  5. <br /><br />
  6.  
  7. <script type="text/javascript">
  8. document.write("The iframe's id: ");
  9. document.write(document.getElementsByTagName("iframe")[0].id);
  10. document.write("<br /><br />");
  11.  
  12. document.write("An alternate way: ");
  13. document.write("<br />");
  14. document.write("The iframe's id: ");
  15. document.write(document.getElementById("frame1").id);
  16. </script>
  17.  
  18. </body>
  19. </html>