TextArea值未显示任何新的换行符 [英] TextArea value not showing any new lines breaks

查看:70
本文介绍了TextArea值未显示任何新的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
textarea的.val()不会'不要考虑新行

Possible Duplicate:
The .val() of a textarea doesn't take new lines into account

当我在带有换行符的文本区域中键入一条消息并从文本区域取回值时,我会得到一个文本区域,这些字符不会保留换行符,并且文本将写成一行.我如何从文本区域获取换行符?我正在使用IE 9和Mozilla,Opera,Safari

I have a text area when i type a message in the text area with newlines and get the value back from the text area the newlines are not preserved and the text is written as one line. how do i get the newlines from the text area?I am using IE 9 and Mozilla, Opera, Safari

var message = $(".chatpaneltext textarea").attr("value");

推荐答案

确保您将换行符\r\n解释为<br />标签.

Make sure you are intepreting your line breaks \r\n as <br /> tags.

text.replace(/\n\r?/g, '<br />'); 

如果您使用的是PHP,则有 nl2br() 函数.或任何其他语言,上面的正则表达式都应该起作用.

If you're using PHP there is the nl2br() function. Or any other language, the above regex should work.

这篇关于TextArea值未显示任何新的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆