使用javascript在div中多行字符串 [英] Multiline string in div using javascript

查看:111
本文介绍了使用javascript在div中多行字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个多行字符串,如下所示:

  var str1 = document.getElementById('text1'); 
var str2 = document.getElementById('text2');
var str = str1.value +\\\
+ str2.value;

我现在想要将这个字符串添加到我在弹出窗口中创建的div中,如下所示:

<$ 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>');

但是我没有在div中使用多行字符串,我该如何解决这个问题?

解决方案

在没有此CSS属性的情况下,换行符不会在HTML中呈现:

  white-space:pre; 

您可以尝试替换 str 为此:

  var str = str1.value +< br /> \\\
+ str2.value;


I have created a multiline string as follows"

var str1 = document.getElementById('text1');
var str2 = document.getElementById('text2');
var str = str1.value + "\n" + str2.value;

I now want to add this string to a div that I create in a popup window as follows:

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>');

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:

white-space: pre;

You can try to replace str to this:

var str = str1.value + "<br/>\n" + str2.value;

这篇关于使用javascript在div中多行字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆