doudieyou5209 2018-10-12 07:18
浏览 727

如何在jquery附加文本中保留空格和换行符

I am submitting textarea using ajax and when I append the response to a class it shows the dummy only when if there is no new line in text area .

HTML

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

ajax code

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

php code

First inserts textarea and print_r new updated text in javascript

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

1条回答 默认 最新

  • doubi4340 2018-10-12 07:25
    关注

    You can achieve it by css, use this and you're done...

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

    also give this css to the textarea also...

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元