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


版本的 Microsoft Internet Explorer 瀏覽器中新引入的IE4文件物件模型(DOM)。IE5和以後版本包含對大多數基本的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>

更新於: 2020 年 6 月 23 日

116 次瀏覽

開啟你的職業生涯

透過完成該課程獲得認證

開始
廣告
© . All rights reserved.