2013-09-26 28 views
0

我想在javascript中放置换行符。我已经使用<br/>, \n and %0D%0A,但没有发生任何事情。如何在JavaScript中放置换行符?

这里是我的代码:

var textpara = 'This is dummy text. It will blink and then show.'; 

我想这一点:

This is dummy text. 
It will blink and then show. 

有什么建议?

+0

您是如何显示或使用字符串? –

+1

是否需要在页面,控制台或警报框中的某处显示文本? – ibtarek

+0

显示周围的代码。 –

回答

1

如果你想显示在控制台中的文本,您可以使用反斜杠换行招:

var textpara = 'This is dummy text. \ 
It will blink and then show.'; 

console.log(textpara); 

或者,像下面这样添加新行:

var textpara = "This is dummy text. \nIt will blink and then show."; 
console.log(textpara); 
1

添加“\ n “应该完成这项工作。

试试这个:

的javascript:浏览器的地址栏上

var textpara = "This is dummy text." + "\n" + "It will blink and then show."; 

alert(textpara); 

我已经测试它和它的作品

0

试试这个:

<script lang="JavaScript" > 
var textpara = 'This is dummy text. <br/>It will blink and then show.'; 
document.write(textpara); 
</script> 

这个工程太。

输出:

This is dummy text. 
It will blink and then show. 
相关问题