[英]How to make text nodes with new lines in it without using “style=white-space: pre”?
I'm trying to get a textnode with new lines in it (my text contains \\n
and x0a
). 我正在尝试使用新行的textnode(我的文本包含
\\n
和x0a
)。 I found the way to do this, using white-space: pre
, and it works, but the problem is that the content doesn't fit to the parent div, I got the new lines in the text, but when the line is long, it goes beyond the window. 我找到了这样做的方法,使用
white-space: pre
,它可以工作,但问题是内容不适合父div,我在文本中得到了新行,但是当行很长时,它超越了窗口。
This is the code: 这是代码:
var textdata = document.createTextNode(text_with_multiples_lines);
PanelBody.style = "white-space: pre;"
PanelBody.appendChild(textdata);
Somebody know how to make new lines inside a textnode without exceeding the window size? 有人知道如何在不超出窗口大小的情况下在textnode中创建新行吗?
Set white-space
to pre-wrap
instead. 将
white-space
设置为pre-wrap
。
This also enables text lines to break as needed to fill the element box :) 这也可以根据需要打开文本行来填充元素框:)
More on that: MDN - white-space 更多内容: MDN - 白色空间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.