我想在javascript中添加换行符。我使用了<br/>, \n and %0D%0A
但没有发生任何事情。
这是我的代码:
var textpara = 'This is dummy text. It will blink and then show.';
我想要这个:
This is dummy text.
It will blink and then show.
有什么建议吗?
答案 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 :(得分:1)
添加“\ n”应该可以胜任。
试试这个:
的javascript:
var textpara = "This is dummy text." + "\n" + "It will blink and then show.";
alert(textpara);
在浏览器的网址栏上。
我已经测试了它并且有效
答案 2 :(得分: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.