[英]append text to a textarea with line breaks
I want to add some strings to a textarea
which are file basenames. 我想在textarea
添加一些字符串作为文件基名。 Everything is fine, but the only problem is that it mixes all the values and there are not any line breaks: 一切都很好,但唯一的问题是它混合了所有的值,没有任何换行符:
var file_name = file.file_name;
var base = new String(file_name).substring(file_name.lastIndexOf('/') + 1);
if(base.lastIndexOf(".") != -1)
base = base.substring(0, base.lastIndexOf("."));
$('textarea#image_Basename').append(base).split('\n');
These are my file basenames: 这些是我的文件基名:
5b0cd65710052633dc5dcac406a382c4
212asaddgcvjh622sdsds22113554dfd
5sd5weea55rr6qasfdjkloijhj665s6a
But after storing the data in to the database and retrieving it, the result I get is: 但是在将数据存储到数据库并检索它之后,我得到的结果是:
5b0cd65710052633dc5dcac406a382c4212asaddgcvjh622sdsds22113554dfd5sd5weea55rr6qasfdjkloijhj665s6a
To preserve newlines that are coming from a database or whatever, replace the newline characters with the HTML entity for a line feed: 

要保留来自数据库或其他内容的换行符,请使用换行符的HTML实体替换换行符: 

base = base.replace("\n", '
');
$('#image_Basename').append(base);
If you're trying to append each string with a newline at the end, just concatenate it onto the string: 如果你试图在结尾追加每个字符串的新行,只需将它连接到字符串上:
$('#image_Basename').append(base + '
');
Also, you're using split on the textarea
jQuery element, which doesn't make sense as it is an object
not a string
. 此外,你在textarea
jQuery元素上使用split,这没有意义,因为它是一个object
而不是一个string
。
My Special thanks to @rink.attendant.6, his second method worked for me :) The answer is: 我特别感谢@ rink.attendant.6,他的第二种方法对我有用:)答案是:
$('#image_Basename').append(base + '
');
After adding this, I got all the file basenames in separate lines! 添加之后,我将所有文件基本名称分开!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.