我刚开始从w3school学习 javascript ,我发现“您只能在 HTML 输出中使用 document.write。如果在文档加载后使用它,整个文档将被覆盖。” 所以我尝试编写以下代码来检查有效性:
<html>
<head>
<title>ashish javascript learning</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p> sample html with javascript </p>
<script>
document.write("<h1>this is heading</h1>");
document.write("<p>this is sample para</p>");
</script>
<script>
if(document.readyState === "complete"){
loaded();
}
function loaded(){
document.write("<p>loading content after the document has been loaded");
}
</script>
</body>
</html>
代码仍然显示旧值并且没有覆盖网页的内容。你能告诉我我做错了什么吗?