1.document.write 是什么
document.write用于向dom中下入数据
document.write(''testGreeting")相当于
document.open();
document.write("testGreeting");
document.close;
document.addEventListener('DOMContentLoaded', function (event) {
document.write("testGreeting");
});
//等同于
document.open();document.write("testGreeting");
document.close();
1.3 当然,只要当前文档还没有用 close() 方法关闭,它所写入的内容就会追加在已有内容的后面。
document.writeln 和 document.write 作用基本一样,区别仅仅是writeln()会在结尾添加一个换行符。
但问题在于,这个换行符是ascii码的换行符,在html渲染页面时不会生效,所以不会有效果,建议使用<br/>
本文详细解释了JavaScript中document.write和writeln方法的功能及差异,并强调了在DOMContentLoaded事件后使用这些方法时页面内容会被清除的特点。

被折叠的 条评论
为什么被折叠?



