[英]Preserve Line Breaks - Input type="text"
I am working on a copy paste script, which works except that there are no line breaks in the paragraphs I am looking to copy.我正在制作一个复制粘贴脚本,除了我要复制的段落中没有换行符外,它可以正常工作。 So, the outcome of pasting is displays all of the text on one line.
因此,粘贴的结果是在一行中显示所有文本。
<input type="text" value="This is the first line
This is the second paragraph
This is the third paragraph" id="myInput">
<button onclick="myFunction(event)">Copy</button>
Example: When I copy this from the button, it pastes as:示例:当我从按钮复制它时,它粘贴为:
This is the first line This is the second paragraph This is the third paragraph这是第一行这是第二段这是第三段
Instead, I want the line to break in between paragraphs if possible相反,如果可能的话,我希望在段落之间换行
I think you can use textarea instead of input.我认为您可以使用 textarea 代替输入。
<textarea id="myInput">This is the first line
This is the second paragraph
This is the third paragraph</textarea>
Instead Use Textarea while inserting data and when you want to show use this function to preserve the line breaks echo nl2br($string);相反,在插入数据时使用 Textarea 并在要显示时使用此 function 来保留换行符 echo nl2br($string);
For example例如
<textarea class="form-control" name="short_desc" required></textarea>
and for frontend echo use following function和前端回声使用以下 function
<?PHP echo nl2br($short_desc);?>
It will preserve the line break and show content with breaks on frontend,它将保留换行符并在前端显示带有换行符的内容,
also remember to keep the Mysql data type text for it.还记得为其保留 Mysql 数据类型文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.