Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách truy cập thuộc tính Document bằng Legacy DOM trong JavaScript

Ví dụ truy cập thuộc tính document qua Legacy DOM:

Ví dụ

<html>
  <head>
    <title> Document Title </title>
    <script>
      function myFunc() {
        var ret = document.title;
        alert("Document Title: " + ret);
        var ret = document.URL;
        alert("Document URL: " + ret);
        var ret = document.forms[0];
        alert("First Form: " + ret);
        var ret = document.forms[0].elements[1];
        alert("Second element: " + ret);
      }
    </script>
  </head>
  <body>
    <h1 id="title">This is main title</h1>
    <p>Nhấn để xem kết quả:</p>
    <form name="FirstForm">
      <input type="button" value="Click Me" onclick="myFunc();" />
      <input type="button" value="Cancel">
    </form>
    <form name="SecondForm">
      <input type="button" value="Don't ClickMe" />
    </form>
  </body>
</html>