HTML DOM write () method
Definition and Usage
write () method of expression can be written HTML or JavaScript code to the document.
grammar
document.write(exp1,exp2,exp3,...)
参数 | 描述 |
---|---|
exp1,exp2,exp3,... | 可选。要写入的输出流。多个参数可以列出,他们将按出现的顺序被追加到文档中 |
Browser Support
All major browsers support write () method
Examples
Example 1
Write some text to the output stream:
<html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
try it"
Example 2
Writes some text to the output stream format:
<html>
<body>
<script>
document.write("<h1>Hello World!</h1><p>Have a nice day!</p>");
</script>
</body>
</html>
<body>
<script>
document.write("<h1>Hello World!</h1><p>Have a nice day!</p>");
</script>
</body>
</html>
try it"
Example 3
write () and writeln () the difference:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>
<p>注意write()方法不会在每个语句后面新增一行:</p>
<script>
document.write("Hello World!");
document.write("Have a nice day!");
</script>
<p>注意writeln()方法在每个语句后面新增一行:</p>
<script>
document.writeln("Hello World!");
document.writeln("Have a nice day!");
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>
<p>注意write()方法不会在每个语句后面新增一行:</p>
<script>
document.write("Hello World!");
document.write("Have a nice day!");
</script>
<p>注意writeln()方法在每个语句后面新增一行:</p>
<script>
document.writeln("Hello World!");
document.writeln("Have a nice day!");
</script>
</body>
</html>
try it"
Document Object