在JavaScript字符串中输入换行符的正确语法?

时间:2013-05-08 21:48:31

标签: javascript jquery

在字符串中插入换行符的正确语法是什么?我试过'\ n'但是这不起作用......?这是有问题的字符串:

    function layer0(){
  document.getElementById('layerinfo').innerHTML = 'The Wembury Quest ran during June   2012 and was very popular in the parish. Over 400 quest packs were collected from the village school post office and local shops. The Quest was designed to encourage residents to go out into the parish and explore their local landscape. This layer shows the results from the letterboxes. For the letterboxes twelve locations were chosen, spread around the parish. They were picked to take participants to very different types of landscape and views. Some of them were places which they had visited before, and some were off the beaten track and were new to some Questers. All of the locations were found on public rights of way.';

4 个答案:

答案 0 :(得分:2)

\n是在字符串中插入换行符的正确语法。您的问题是您不希望在字符串中插入换行符。您希望在字符串中插入文本<br>。在字符串中插入文本<br>的正确语法是<br>

答案 1 :(得分:1)

您希望此中断显示在HTML页面中吗?

<br> 

然后

答案 2 :(得分:1)

<br />标记,正如您使用innerHTML

一样

答案 3 :(得分:0)

您可以使用<br>标记进行换行