写到 HTML 文档 出于测试目的,您可以将JavaScript直接写在HTML 文档中: - <!DOCTYPE html>
- <html>
- <body>
- <h1>我的第一个 Web 页面</h1>
- <p>我的第一个段落。</p>
- <script>
- document.write(Date());
- </script>
- </body>
- </html>
复制代码请使用 document.write() 仅仅向文档输出写内容。 如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖。 - <!DOCTYPE html>
- <html>
- <body>
- <h1>我的第一个 Web 页面</h1>
- <p>我的第一个段落。</p>
- <button onclick="myFunction()">点我</button>
- <script>
- function myFunction() {
- document.write(Date());
- }
- </script>
- </body>
- </html>
复制代码
|