![](/img/trans.png)
[英]keep input to 2 line breaks consecutively in textarea (preview div before submit)
[英]Keep line breaks in outputed div from textarea
$("textarea").blur(function() { $("div").html($("textarea").val()); }); $("textarea").blur();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <textarea style="height:50px;"> 1. test 2. test 3. test </textarea> <div style="word-break: break-all;"></div>
我想使文本以與textarea中顯示的確切方式顯示在div中。
我試圖用word-break
等css div,但沒有一個有效。
注意:具體來說,我只是想知道如何在div中做到這一點。
嘗試設置white-space:pre;
或white-space:pre-wrap;
到了div。
$("textarea").blur(function() { $("div").html($("textarea").val()); }); $("textarea").blur();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <textarea style="height:50px;"> 1. test 2. test 3. test </textarea> <div style="white-space:pre;"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.