【发布时间】:2011-10-07 22:24:06
【问题描述】:
我在 Stackoverflow 上搜索了好几个小时,但没有人的解决方案适用于 Internet Explorer 8。
我收到了一个这样的纯文本文档:
This is a legal agreement ("Agreement") between you and ...
License
Subject to you continued and ongoing compliance with the terms and conditions set ...
Restrictions
Except as otherwise explicitly provided in this Agreement, ...
Ownership
Except for this license granted to you, as between you and ...
Disclaimer of Warranties
Use at your own risk. ...
而且我需要用双换行符 (<br/><br/>) 替换换行符(换行符、回车符,无论你想如何称呼它们),以使文本看起来更正常。
jQuery convert line breaks to br (nl2br equivalent) 的 nl2br 函数在大多数浏览器中都能正常工作。但是,我的一个客户使用的是 IE8。
继续尝试使用 IE8(或设置为 IE8 模式的现代 Internet Explorer)的 nl2br 功能;它不起作用。
有谁知道为什么它在 IE8 中不起作用?以及如何实现目标?
附:我在这里放了一些代码http://jsfiddle.net/L2Ufj/2/,奇怪的是它可以通过 jsfiddle 在 IE8 中运行,但是如果你将它复制到其他地方并真正运行它,它就无法在 IE8 中运行。
【问题讨论】:
-
"(...) 但是如果你将它复制到其他地方并真正运行它,它将无法在 IE8 中工作" --- jsFiddle 没有做任何魔法。确保您不在 jsFiddle 中包含任何库。如果它仍然有效,那么无论您将代码复制到何处,您都做错了。无论如何,不要使用元素节点的
innerHTML,而是尝试获取文本节点的nodeValue。
标签: javascript jquery internet-explorer-8 newline line-breaks