如何在JavaScript警告框中添加新行?
当前回答
适用于\n,但如果脚本是java标记,则必须编写\\\n
<script type="text/javascript">alert('text\ntext');</script>
or
<h:commandButton action="#{XXXXXXX.xxxxxxxxxx}" value="XXXXXXXX"
onclick="alert('text\\\ntext');" />
其他回答
在c#中,我做到了:
alert('Text\\n\\nSome more text');
它显示为:
文本 更多文本
适用于\n,但如果脚本是java标记,则必须编写\\\n
<script type="text/javascript">alert('text\ntext');</script>
or
<h:commandButton action="#{XXXXXXX.xxxxxxxxxx}" value="XXXXXXXX"
onclick="alert('text\\\ntext');" />
当你想用javascript写一个php变量的alert时,你必须在“\n”之前加一个“\”。 相反,弹出的警告不起作用。
ex:
PHP :
$text = "Example Text : \n"
$text2 = "Example Text : \\n"
JS:
window.alert('<?php echo $text; ?>'); // not working
window.alert('<?php echo $text2; ?>'); // is working
alert("text\nnew Line Text");
文档:Window.alert ()
Firefox:
铬:
优势:
Alert ("some text\nmore text in a new line");
alert(“第 1 行\n第 2 行\n第 3 行\n第 4 行\n第 5 行”);