使用javascript在div中多行字符串 [英] Multiline string in div using javascript
问题描述
我创建了一个多行字符串,如下所示:
var str1 = document.getElementById('text1');
var str2 = document.getElementById('text2');
var str = str1.value +\\\
+ str2.value;
我现在想要将这个字符串添加到我在弹出窗口中创建的div中,如下所示: 但是我没有在div中使用多行字符串,我该如何解决这个问题? 在没有此CSS属性的情况下,换行符不会在HTML中呈现: 您可以尝试替换 I have created a multiline string as follows" I now want to add this string to a div that I create in a popup window as follows: But I do not get a multiline string in the div. How do I solve this problem? Line breaks are not rendered in HTML without this CSS property: You can try to replace
这篇关于使用javascript在div中多行字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $ ('','Full_text','width = 600,height = 600');
myWindow.document.write('< div id =div1 style =position:absolute; left:10px; width:580px; top:30px; height:550px; overflow:auto;>'+ str +'< / div>');
white-space:pre;
str
为此:
var str = str1.value +< br /> \\\
+ str2.value;
var str1 = document.getElementById('text1');
var str2 = document.getElementById('text2');
var str = str1.value + "\n" + str2.value;
myWindow=window.open('','Full_text','width=600,height=600');
myWindow.document.write('<div id="div1" style="position: absolute; left: 10px; width: 580px; top: 30px; height: 550px; overflow: auto;">' + str + '</div>');
white-space: pre;
str
to this:var str = str1.value + "<br/>\n" + str2.value;