JavaScript:写入HTML输出 document.write
<html>
<bosy>
<p>
JavaScript 能够直接写入 HTML 输出流中:
</p>
<script>
document.write("<h1>This is a deading</h1>");
document.write("<p>This is a paragraph</p>");
</script>
<p>
您只能在 HTML 输出流中使用 <strong>document.write</strong>.
如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。
</P>
</body>
</html>
JavaScript:对事件做出反应
alert()函数在JavaScript中并不常用,但它对于代码测试非常方便。
<html>
<body>
<h1>爱上了W3</h1>
<P>
JavaScript 能够对事件做出反应。比如对按钮的点击:
</p>
<button type = "button" onclick = "alert('Welcome!')">点击这里</button>
<button type = "button" onclick = "alert('爱上W3')">halo</button>
</body>
</html>