【问题标题】:How to preserve white spaces and new line in jquery append text如何在jquery追加文本中保留空格和换行符
【发布时间】:2019-03-17 09:01:52
【问题描述】:

我正在使用 ajax 提交 textarea,当我将响应附加到一个类时,它仅在文本区域中没有新行时才显示虚拟对象。

HTML

   <p id="updateres_n"></p>
   <div class="update_res"></div>

ajax 代码

success: function(response){
     document.getElementById('upd_msg').innerHTML="updated";
     $('.update_res').append(response);
  }  

php代码

首先在javascript中插入textarea和print_r新的更新文本

<script>
 document.getElementById('updateres_n').innerHTML="<?php print_r (nl2br($updated_text));?>";
</script>

【问题讨论】:

  • 你的问题不清楚你面临的问题是什么
  • 使用 ajax i 提交文本并通过 jquery 和 javascript 它显示插入文本的虚拟,但虚拟仅在文本中没有新行但我想显示新行​​时显示文本。 . 什么不清楚??
  • 此链接可以提供帮助:stackoverflow.com/questions/13482507/…
  • 不,不清楚。 dummy of the inserted text 是什么?请显示输入以及预期和实际输出 - 如果需要,请使用图片
  • 预览我的朋友

标签: php jquery html ajax append


【解决方案1】:

你可以通过css来实现,使用这个就完成了……

.update_res {
    white-space: pre-wrap;
}

也将这个 css 给 textarea...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2012-03-18
    相关资源
    最近更新 更多