如何使用 W3C DOM 方法访问文档属性?

htmljavascriptprogramming scripts更新于 2024/6/24 11:06:00

这是 IE4 文档对象模型 (DOM),在 Microsoft Internet Explorer 浏览器第 4 版中引入。IE 5 及更高版本支持大多数基本的 W3C DOM 功能。

示例

要使用 W3C DOM 方法访问文档属性,您可以尝试运行以下代码 −

<html>
   <head>
      <title> Document Title </title>
      <script type="text/javascript">
         <!--
            function myFunc() {
               var ret = document.getElementsByTagName("title");
               alert("Document Title : " + ret[0].text );

               var ret = document.getElementById("heading");
               alert(ret.innerHTML );
            }
         //-->
      </script>
   </head>
   <body>
      <h1 id="heading">This is main title</h1>
      <p>Click the following to see the result:</p>

      <form id="form1" name="FirstForm">
         <input type = "button" value = "Click Me" onclick = "myFunc();" />
         <input type = "button" value = "Cancel">
      </form>

      <form d="form2" name="SecondForm">
         <input type = "button" value = "Don't ClickMe"/>
      </form>
   </body>
</html>

相关文章