【问题标题】:displaying stored data in textarea在 textarea 中显示存储的数据
【发布时间】:2015-12-04 22:15:24
【问题描述】:

我将数据存储在一个 YAML 文件中,该文件是在特定日期从 textarea(html 页面)接收到的。

在 YAML 中它以这种格式存储:

09_09_2015: ! "hello this is sireesha\n 1.some information \n2.some information"

当我从 YAML 获取这些数据并将其显示在文本区域中时,它显示为:

"hello this is sireesha\n 1.some information \n2.some information"

我怎样才能克服这个问题并将此文本显示为

hello this is sireesha
   1.some information
   2.some information

在文本区域中?

【问题讨论】:

  • 如果是 javascript 将 \\n 替换为 \r\n。像这样:TextareaElement.value = TextareaElement.value.replace("\\n", "\r\n");。我不知道红宝石
  • 您尝试过什么,您使用哪种语言将其呈现到文本区域?
  • @suresh 我认为<br> 不会在 textarea 中工作。会吗?
  • @TechJS 对不起..是的,它不起作用..我需要这样的东西 .
  • 在jquery中绘制数据前,将数据存入一个变量,使用variable.replace("\n","");

标签: jquery html ruby yaml


【解决方案1】:

使用 jquery .text() , Working demo here,'toTest' 是你的文本区域的id。

$("#toTest").val($("<div/>").html("hello this is sireesha \n 1.some information \n2.some information").text());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-18
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    相关资源
    最近更新 更多