簡體   English   中英

保留換行符 - Input type="text"

[英]Preserve Line Breaks - Input type="text"

我正在制作一個復制粘貼腳本,除了我要復制的段落中沒有換行符外,它可以正常工作。 因此,粘貼的結果是在一行中顯示所有文本。

 <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>

示例:當我從按鈕復制它時,它粘貼為:

這是第一行這是第二段這是第三段

相反,如果可能的話,我希望在段落之間換行

我認為您可以使用 textarea 代替輸入。

<textarea id="myInput">This is the first line
 
This is the second paragraph
 
This is the third paragraph</textarea>

相反,在插入數據時使用 Textarea 並在要顯示時使用此 function 來保留換行符 echo nl2br($string);

例如

    <textarea class="form-control" name="short_desc" required></textarea>

和前端回聲使用以下 function

<?PHP echo nl2br($short_desc);?>

它將保留換行符並在前端顯示帶有換行符的內容,

還記得為其保留 Mysql 數據類型文本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM