document.write一次重置主体 [英] document.write resets body once
问题描述
在加载正文后(通过onclick事件)使用document.write时,它将覆盖整个正文.我想要这是我想要实现的目标.但是,当我再次执行此操作时,它只是添加到先前的内容中.为什么它第一次覆盖所有内容,而仅在下一次添加?
如果未打开文档供编写,则调用document.write
将自动调用document.open
.
第一次调用document.write
时,浏览器已加载文档并因此将其关闭以进行写入.这会调用document.open
,它会擦除现有文档并创建一个新文档以写入.
由于浏览器未加载此内容,因此它不会自动关闭以进行写入,因此在再次调用docment.write
时将附加内容.如果要清除内容,可以显式调用document.close
和document.open
.
有关更多详细信息,请参见 https://developer.mozilla.org/en/document.write ./p>
When I used document.write after loading the body (via onclick event), it overwrites the entire body. I want this for what I'm trying to achieve. However, when I do it again, it simply adds on to the previous content. Why does it overwrite everything the first time and only add on the next?
If the document isn't open for writing, then calling document.write
will automatically call document.open
.
The first time you call document.write
, the browser has loaded the document and thus closed it for writing. This calls document.open
which wipes out the existing document and creates a new one to write into.
Since the browser isn't loading this, it doesn't automatically close it for writing, so the content is appended when you call docment.write
again. You can explicitly call document.close
and document.open
if you want to wipe out the content.
See https://developer.mozilla.org/en/document.write for more details.
这篇关于document.write一次重置主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!