JS中方法document.write() 页面覆盖问题

document.write()一般用于页面 onload 的时候。如果页面已经 onload 完了,也就是页面加载完成了,再调用docume.write()的话,那么,整个 HTML 页面将被覆盖

 

<html>
<head>
<title>form</title>
<head>
<body onload="alert('xxxx');document.write('onloadhtml');">
    <p>段落1</p>
    <script type="text/javascript">
        document.write("加载中html");
    </script>
</body>
<html>

所以下面代码结果为

先输出

段落1

加载中html

然后弹出对话框

最后onloadhtml 覆盖整个页面。

onloadhtml

 

posted @ 2016-01-11 22:45  holy_night  阅读(2038)  评论(0编辑  收藏  举报