FF 和 IE - 在文本区域中处理 \n 的方式
我正在用 jeditable 做一个文本区域。内容是从数据库保存和加载的。但我在 IE 和 FF 处理换行符的方式上遇到了一些问题。
经过一些调试后,我发现 FF 中有一个神秘的行为。例如,如果我在文本区域中输入:
1
2
它将返回
1<br>2
Which is Fine。但如果我写:
1
2
3
它返回
1<br>2<br>
3
怎么来的?我应该如何对这种异常行为进行正则表达式。
自动取款机。我正在做这个正则表达式:
data : function(value, settings) {
/* Convert <br> to newline. */
retval = value(/<br[\s\/]?>/gi, '\n');
return retval;
},
在 IE 中工作正常,但在 FF 中(由于这种行为)它返回的换行符比预期的要多。
你能帮忙吗?
提前致谢
Im doing a textarea with jeditable. The content is saved and loaded from a database. But im having some problems in the way IE and FF handles linebreaks differently.
After some debugging i've found a mysterious behavior in FF. For example if i input in textarea:
1
2
It will return
1<br>2
Which is fine. But if i write:
1
2
3
It returns
1<br>2<br>
3
How come? And how am i supposed to do regexp on this abnormal behaviour.
Atm. im doing this regexp:
data : function(value, settings) {
/* Convert <br> to newline. */
retval = value(/<br[\s\/]?>/gi, '\n');
return retval;
},
Which works fine in IE, but in FF (because of this behaviour) it returns more linebreaks than supposed to.
Can you help ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望文本中没有换行符,为什么不在将
转换为换行符之前将它们删除呢?If you're expecting the text to have no newlines in it, why not just strip them out before you convert the
<br>
s to newlines?