
Document 對象
write() 方法可向文檔寫入 HTML 表達式或 JavaScript 代碼。
document.write(exp1,exp2,exp3,...)
參數
描述
exp1,exp2,exp3,...
可選。要寫入的輸出流。多個參數可以列出,他們将按出現的順序被追加到文檔中
所有主要浏覽器都支援 write() 方法
向輸出流寫入一些文本:
<html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
向輸出流寫入一些格式文本:
document.write("<h1>Hello World!</h1><p>Have a nice day!</p>");
write() 與 writeln() 的差別:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(runoob.com)</title>
</head>
<p>注意write()方法不會在每個語句後面新增一行:</p>
document.write("Have a nice day!");
<p>注意writeln()方法在每個語句後面新增一行:</p>
document.writeln("Hello World!");
document.writeln("Have a nice day!");
