我想要这样的输出:
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
添加新行。
请帮助我理解这一点。
答案 0 :(得分:2)
如果您将HTML注入某个div,则还应使用HTML完成新行 - <br />
。
document.getElementById("result").innerHTML =
'Your total purchase cost is Rs' + result + '<br />Thank You!';