簡體   English   中英

如何使用document.write()將標簽寫為字符串?

[英]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 = '&gt;h1&lt; Hello! &gt;/h1&lt;';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM