méthode DOM HTML d'écriture ()
Définition et utilisation
méthode write () d'expression peut être écrit du code HTML ou JavaScript au document.
grammaire
document.write(exp1,exp2,exp3,...)
参数 | 描述 |
---|---|
exp1,exp2,exp3,... | 可选。要写入的输出流。多个参数可以列出,他们将按出现的顺序被追加到文档中 |
support du navigateur
Tous les principaux navigateurs supportent méthode write ()
Exemples
exemple 1
Ecrire un texte dans le flux de sortie:
<html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
<body>
<script>
document.write("Hello World!");
</script>
</body>
</html>
Essayez »
exemple 2
Ecrit un texte au format de flux de sortie:
<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>
Essayez »
exemple 3
écrire () et writeln () la différence:
<!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>
Essayez »
Document Object