带有换行符的文本区域的数据
I have a weird problem. I have a simple textarea, Once a save button is clicked I save that data using an angular controller. Then once an update button is clicked I update a row in that data base, that one of that rows fields is the data from that textarea.
我有个奇怪的问题。我有一个简单的textarea,一旦单击save按钮,我将使用一个角度控制器保存数据。点击更新按钮后,我更新数据库中的一行,其中一个行字段就是来自该textarea的数据。
So far so good, and the update is done ok, the problem begins when I break lines in the textarea, for example, I type: "Hi guys, This is another row"
到目前为止,一切都很好,更新也完成了,问题开始了当我在textarea中中断行,例如,I类型:“嗨,伙计们,这是另一行”
I checked that data and when I save it in the controller, and when I get it back from the server it looks like this: "Hi guys,↵This is another row" seems ok, but when I place it inside a div I get the following: "Hi guys,This is another row"
我检查数据,当我将它保存在控制器,当我把它从服务器是这样的:“嗨,伙计们,↵这是另一个行”似乎是好了,但是当我把它在一个div我得到以下:“嗨,伙计们,这是另一个行”
Where did the line break go? and why is it not displaying?
断线在哪里?为什么它不显示?
I tried bunch of things, like changing the newline to <br>
once send to the database, later on switching it back to newline, nothing seems to work...
我尝试了很多方法,比如将换行符改为
,一旦发送到数据库,然后将它切换回换行符,似乎没有任何效果……
Any help would be appreciated.
如有任何帮助,我们将不胜感激。
3 个解决方案
#1
3
Okay - what you need to do is use white-space:pre-wrap;
where you display the data from the database.
好的,你需要做的是使用空白:预包装;显示来自数据库的数据。
Example:
例子:
<?php
echo '<p style="white-space:pre-wrap;">'.$yourVarWithWhiteSpace.'</p>';
?>
更多相关文章
- 使用jQuery导出JSON(外部文件)导入数据的度假输出
- 我应该如何显示包含XML数据源的表?
- 只有在读取数据库后才选择(案例)(开关)
- 将JavaScript函数的值插入SQL Server数据库
- js中ajax获取json数据遍历提示undefined
- JS数据类型(一)
- 在单页中使用ajax和php上传多个表单数据
- 在phonegap上从服务器获取数据
- javascript 数据类型转换