如何使用W3C DOM方法訪問文件屬性?


IE 4文件物件模型(DOM)引入在微軟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>

更新日期: 23-6月-2020

115次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告