innerHtml 和 insideText 破坏 Internet Explorer 中的选项卡

发布于 2024-09-14 01:59:14 字数 221 浏览 2 评论 0原文

我想获取文本区域的内容并将其放入

 中。问题是,如果我将 pre 的 innerHTML-property 设置为 textarea 的值,所有选项卡和换行符都将在 Internet Explorer 中删除。如果我使用innerText而不是innerHtml,我会得到换行符,但选项卡仍然消失。在其他浏览器中运行良好。

有解决办法吗?

I want to take the content of a textarea and put it in a <pre>. Problem is that if i set the innerHTML-property of the pre to the value of the textarea all tabs and linebreaks will be removed in Internet Explorer. If i use innerText instead of innerHtml i will get the line-breaks but tabs still disappear. Works fine in other browsers.

Is there a solution for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不回头走下去 2024-09-21 01:59:14

创建 DOM 文本节点:

pre.innerHTML= '';
pre.appendChild(document.createTextNode('A\tB\r\nC'));

Windows 风格的换行符 (\r\n) 是伪造的(DOM 内容应始终将换行符规范化为 \n),但似乎是由于某种原因在 IE 中是必需的。

Create a DOM Text node:

pre.innerHTML= '';
pre.appendChild(document.createTextNode('A\tB\r\nC'));

The Windows-style newline (\r\n) is bogus (DOM content should always have newlines normalised to \n), but seems to be necessary in IE for some reason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文