[英]How to write tags as strings using document.write()?
是否可以使用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<';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.