HTML DOM write () metode
Definisi dan Penggunaan
write () metode ekspresi dapat ditulis HTML atau kode JavaScript untuk dokumen.
tatabahasa
document.write(exp1,exp2,exp3,...)
参数 | 描述 |
---|---|
exp1,exp2,exp3,... | 可选。要写入的输出流。多个参数可以列出,他们将按出现的顺序被追加到文档中 |
Dukungan Browser
Semua browser utama mendukung write () metode
contoh
contoh 1
Menulis beberapa teks ke output stream:
<html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
Coba »
contoh 2
Menulis beberapa teks ke format output stream:
<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>
Coba »
contoh 3
menulis () dan writeln () perbedaan:
<!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>
Coba »
Document Object