[英]InnerHTML or InnerText for outputting html tags as is
I am trying to use innerHTML
or innerText
to output a HTML basic document.我正在尝试使用
innerHTML
或innerText
来 output 一个 HTML 基本文档。 I am making a website tutorial so I am trying to output the HTML tags as is... I can provide code if needed.我正在制作一个网站教程,所以我正在尝试 output HTML 标签原样......如果需要,我可以提供代码。
Use .textContent
instead so that characters with special meaning in HTML are not interpreted as HTML.请改用
.textContent
,以便 HTML 中具有特殊含义的字符不会被解释为 HTML。
const pre = document.querySelector('pre'); pre.textContent = `<div>Some content</div>`;
<pre></pre>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.