Javascript: Textarea to html, how to save exact whitespaces count in html?
How to save exact whitespace count between words from textarea when putting it's value into html?
&开发者_运维问答lt;textarea>word "10 whitespaces here" word "20 whitespaces here" word</textarea>
html:
<div style="width:50px;overflow:hidden;">word "10 whitespaces here" word "20 whitespaces here" word</div>
So that all text inside div would be visible.
Assuming you are creating your div from scratch, here is a way to replace the spaces with the HTML-friendly
.
var newDiv = document.createElement("div");
// the below replaces two spaces with " "
newDiv.innerHTML = value.replace(/ /g, " ");
Use CSS property white-space: pre
or replace spaces with
.
精彩评论