php回显带有新行'\n'的警报消息不起作用

New*_*bie 2 javascript php string

我有一条消息要使用 alert() 显示

$message = "No result found for the following info:Name: ".$FullName."IC: ".$ID." in database.";
echo "<script>alert('".$message."'); window.history.back();</script>";
Run Code Online (Sandbox Code Playgroud)

这是有效的,但如果我在消息中添加一个新行 '\n'

$message = "No result found for the following info:\nName: ".$FullName."\nIC: ".$ID." in database.";
Run Code Online (Sandbox Code Playgroud)


它不会显示弹出消息。问题是什么?

yer*_*rgo 5

编辑它不要在 PHP 中更改为换行符,而是在 javascript 中:

'No result found for the following info:\nName: '.$FullName.'\nIC: '.$ID.' in database.'
^                                               ^           ^      ^     ^             ^
Run Code Online (Sandbox Code Playgroud)

或者通过添加额外的反斜杠:"\\n".

根据 Panther 的说法,也是真理:使用'alert("' . $message . '")'.