我的学习笔记

vuePress-theme-reco 我的学习笔记    2020 - 2024
我的学习笔记 我的学习笔记

Choose mode

  • dark
  • auto
  • light
时间轴
github
author-avatar

我的学习笔记

24

Article

17

Tag

时间轴
github

JavaScript杂记

vuePress-theme-reco 我的学习笔记    2020 - 2024

JavaScript杂记

我的学习笔记 2021-07-02 js

document.write() 在代码执行过程中执行会将内容添加至页面中;如果当代码执行完毕再执行document.write()会将原有页面的内容全部覆盖。

代码在执行过程中执行document.write()

<!DOCTYPE html>
<html>
<body>

<h1>我的第一个 Web 页面</h1>

<p>我的第一个段落。</p>

<script>
document.write(Date());
</script>

</body>
</html>

当代码全部执行完再执行document.write()会将原有的代码进行覆盖

<!DOCTYPE html>
<html>
<body>

<h1>我的第一个 Web 页面</h1>

<p>我的第一个段落。</p>

<button onclick="myFunction()">点我</button>

<script>
function myFunction() {
   document.write(Date());
}
</script>

</body>
</html>