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

Thay thế nội dung tài liệu với JavaScript

Sử dụng document.open(), document.write(), document.close() để ghi đè toàn bộ nội dung trang.

Ví dụ

<!DOCTYPE html>
<html>
  <body>
    <p>Click để thay thế nội dung này.</p>
    <button onclick="Display()">Replace</button>
    <script>
      function Display() {
        document.open("text/html", "replace");
        document.write("<p>Demo text!</p>");
        document.close();
      }
    </script>
  </body>
</html>