如何在JavaScript警告框中添加新行?
当前回答
\n将不会工作,如果你在Java代码中:
<% System.out.print("<script>alert('Some \n text')</script>"); %>
我知道这不是答案,只是觉得这很重要。
其他回答
我使用了:"\n\r" -它只能在双引号中使用。
var fvalue = "foo";
var svalue = "bar";
alert("My first value is: " + fvalue + "\n\rMy second value is: " + svalue);
will alert as:
My first value is: foo
My second value is: bar
\n将放入新行- \n是新行的控制代码。
警报(“第 1 行\n第 2 行”);
Alert ("some text\nmore text in a new line");
输出:
一些文本 新行中有更多文本
谢谢你的提示。使用“+”号是我能让它工作的唯一方法。这是加法函数的最后一行。我自己也在学习JavaScript:
alert("Line1: The sum is " + sum + "\n" + "Line 2");
当你想用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