是否可以使用document.write()将标记写为字符串?
var myWindow= window.open('', '', 'width=500, height=500');
document.write("<h1> Hello! </h1>"
这会写你好!但我希望的输出是->您好!标签为
<h1>
和</h1>
。 最佳答案
如果设置正文的textContent
属性,它将知道它是文本而不是HTML(因此它将为您编码字符):
document.body.textContent = '<h1> Hello! </h1>`
除此以外:
document.body.innerHTML = '>h1< Hello! >/h1<';
关于javascript - 如何使用document.write()将标签写为字符串?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25734868/