HTML-DOM Methode write ()
Definition und Verwendung
write () -Methode des Ausdrucks kann auf das Dokument HTML oder JavaScript-Code geschrieben werden.
Grammatik
document.write(exp1,exp2,exp3,...)
参数 | 描述 |
---|---|
exp1,exp2,exp3,... | 可选。要写入的输出流。多个参数可以列出,他们将按出现的顺序被追加到文档中 |
Browser-Unterstützung
Alle gängigen Browser Methode write () unterstützen
Beispiele
Beispiel 1
Schreiben Sie einen Text in den Ausgabestream:
<html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
Versuchen »
Beispiel 2
Schreibt einen Text in den Ausgabestream-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>
Versuchen »
Beispiel 3
write () und writeln () den Unterschied:
<!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>
Versuchen »
Document Object