如何识别Web文本区域中的新行 [英] How to recognize the new lines from web text area

查看:112
本文介绍了如何识别Web文本区域中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文字区域。

即使我输入多行文本,它也会将整个文本作为var变量中的一行。



例如:HI,

i很好。



当我把它变成变量我想要这个

HI,'/ br tag'我很好。

但是好像是我很好。



请帮助我这个


提前致谢。

I have a text area.
even when i type text with multiple lines it was taking entire text as a single line in var variable.

example:
i am good.

when i get this into variable i want this as
" '/br tag' i am good. "
but it is coming like " i am good. "

Please help me in this

Thanks in advance.

推荐答案

TextArea使用carrage-return('\ r'),换行('\ n')样式换行符号。您甚至可能在调试器中看不到字符,因为它们将被解释为这些显示中的新行。



它们可能会通过换行输出到您的html页面:

TextArea uses carrage-return('\r'), line-feed('\n') style chars for line breaks. You may not see the chars even in debugger as they will be interpreted to new lines in those displays.

They may well be output to your html page with the line break:
<div>
HI,
i am good. 
</div>



但浏览器会在没有< br />的情况下忽略它,正如您所说的那样



试试这个:


but the browser will ignore it without the <br />, as you correctly stated

Try this:

//C#
var stringAsHtml = myTextArea.Text.Replace("\r\n", "<br />\r\n");




//Javascript
var stringAsHtml =


(选择器)。 val()。替换( \\\\ n &l t; br /> \\\\ n);
(selector).val().Replace("\r\n", "<br />\r\n");





如果将保留换行符标记,使其更容易阅读。然后输出如下:





If will preserve the line break in the markup to make it easier to read. the output with then be like this:

<div>
HI, <br />
i am good.
</div>







希望有所帮助^ _ ^




Hope that helps ^_^


这篇关于如何识别Web文本区域中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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