![](/img/trans.png)
[英]Using JavaScript's Document.write() to create a HTML link
[英]document.write() works inline but not using jQuery's .html()
如果在页面加载时我的document.write
已经有一个document.write
,它将仅在调用该方法的位置进行写操作。 例如:
<div id="d1">
existing text <script>document.write('& doc written text');</script>
</div>
<div>footer</div>
将呈现为<div id="d1">existing text & doc written text</div><div>footer</div>
但是,如果我要使用jQuery更新div中的html,例如
$("#d1").html("another approach <script>document.write('wipes out the screen');</script>");
最后,我只用wipes out the screen
b / c结束了它,它基本上摆脱了文档中的所有内容,而只写了内联脚本所在的位置。 如何使用包含document.write()
的值来.html()
,但使其行为与开始时在dom中的行为相同(请参见第一个示例)。 谢谢!
如果页面已完全写入,则不能使用document.write()。 您无法更改其行为。 您需要重新考虑自己在做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.