在html textarea中显示换行符 [英] Show newlines in html textarea

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

问题描述

我有一个textarea,我将它的文本设置为一个带有 \\\
的字符串。我希望这代表了一个换行符。

  $(#ConfirmEmailText)。text(test\\\
\\\
test\\\
test);

然而,我只是看起来像一个标签而不是一个新行。 b
$ b

如果我在框中添加一些额外的文本,然后按回车键。我可以看到单独的文本。然后我把这个文本放在这个盒子里,然后通过电子邮件发送出去。在电子邮件中,当我添加一些文本在电子邮件中显示为换行符时, \\\
和我的[输入] ...



为什么在我的textarea中显示不正确?

谢谢!

解决方案

设置而不是 innerText ;

  $(#ConfirmEmailText)。val(test \\\
\\\
test\\\
test);


I have a textarea and I set its text to a string with \n in it. I would expect that to represent a line break.

$("#ConfirmEmailText").text("test\n\ntest\ntest");

However, I just get what looks like a tab rather than a new line.

If I add some additional text to the box, and press enter. I can see the text on seperate line. I then take the text in this box and send it in an email. In the email both the \n and my [enter]s from when I added some text show up as newlines in the email...

Why does this not display correctly in my textarea?

Thanks!

解决方案

Set the value not the innerText;

$("#ConfirmEmailText").val("test\n\ntest\ntest");

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

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