如何在div输出中添加新行

时间:2017-11-28 09:41:28

标签: javascript html

我想要这样的输出:

   1st line-  " Your total purchase cost is Rs.980"
   2nd line-            Thank You!

我的代码段:

document.getElementById("result").innerHTML = 'Your total purchase cost is Rs' +result;
<div id = "result"> </div>

我尝试添加:

document.getElementById("result").innerHTML = 'Your total purchase cost is Rs' +result <br> 'Thank You!';

并使用\n添加新行。

请帮助我理解这一点。

1 个答案:

答案 0 :(得分:2)

如果您将HTML注入某个div,则还应使用HTML完成新行 - <br />

document.getElementById("result").innerHTML =
  'Your total purchase cost is Rs' + result + '<br />Thank You!';