jQuery的textarea的追加换行行为 [英] jQuery textarea append newline behavior
问题描述
我想追加一个字符串,它结束换行符使用jQuery一个textarea。但是,不同的令牌换行显示,火狐3.5和IE8不同的行为,我似乎无法找到一种方法来使用的东西,这两个浏览器的工作原理。
I'm trying to append a strings which end in newlines to a textarea using jQuery. However, different newline tokens show different behavior in Firefox3.5 and IE8, and I can't seem to find a way to use something that works for both browsers.
-
\\ n
在FF但不是在IE -
< BR />
和\\ r \\ n
在IE浏览器而不是在工作
FF - 没有运气使用
< pre>< / pre>
标签或者
\n
works in FF but not in IE<br/>
and\r\n
work in IE but not in FF- No luck using
<pre></pre>
tags either
我见过的对IE的innerHTML问题的信息,但我不完全知道如何最好地在jQuery的解决这个问题。感谢您的帮助!
I've seen info on the IE innerHTML issue but I'm not exactly sure how to best approach this problem in jQuery. Thanks for any help!
推荐答案
不知道你是如何设置textarea的内容,但如果你使用jQuery的 VAL
方法 \\ n
都能正常工作在Firefox和IE浏览器(包括IE8):
Not sure how you are setting the textarea content, but if you use the jQuery val
method, \n
works consistently in Firefox and IE (Including IE8):
var txt = $("textarea#idhere");
txt.val( txt.val() + "\nSomething here\n\nAgain");
原因textarea的展示:
Causes the textarea to display:
现有的内容结果
和换行(如有)。结果
这里的东西
Existing content
and linebreaks if any.
Something here
再次
您可以在这里看到演示,在FF和IE8的工作原理:演示 | 来源
You can see a demo here that works in FF and IE8: Demo | Source
这篇关于jQuery的textarea的追加换行行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!