哦?那你能告诉我<html> <head> </head> <body> <p>This is a page.</p> <script> window.onload = function(){ document.write('<p>This is another page.</p>'); } </script> </body> </html><html> <head> </head> <body> <p>This is a page.</p> <script> document.write('<p>This is another page.</p>'); </script> </body> </html>是怎么回事吗,大侠?
其实load完之后 你调用的func其实是没有write操作的
<html>
<head></head>
<body>good!</body>
</html>
原因在于你之后调用的时候,page已经加载完毕了
<head>
</head>
<body>
<p>This is a page.</p>
<script>
window.onload = function(){
document.write('<p>This is another page.</p>');
}
</script>
</body>
</html><html>
<head>
</head>
<body>
<p>This is a page.</p>
<script>
document.write('<p>This is another page.</p>');
</script>
</body>
</html>是怎么回事吗,大侠?
你这个例子如何和你的描述是一个意思,那我向你道歉。
我对文字的理解始终都有误区,之前经常犯类似的错误
不过我觉得如果这样说的话可以解释:
如果一个事件处理程序调用document.write,且文档已解析完毕,该处理程序被调用时,结果会被覆盖。
<script>
function $(o){return document.getElementById(o)}
function fuc() {
//document.write("good!");//web页面中只有一个“good!”,为什么每次都清除以前的内容再写入?
//document.body.innerHTML=Math.random();这条语句能生成随机数说明setTimeout执行良好
$('test').innerHTML += 'good!';
setTimeout("fuc()",1000);
}
</script>
<body onload="fuc();" id="test">
</body>
</html>这样。
document.write()和document.writeln() 我试验过根本没区别啊,后者多输出一个换行符,可是换行符在html中会被忽略的啊我的理解有误吗?
<head>
</head>
<body>
<p>This is a page.</p>
<script>
document.writeln('<pre>one');
document.write('two');
document.writeln('three');
document.writeln('</pre>');
</script>
</body>
</html>