基本上,我试图通过 PHP 调用 Javascript 警报。虽然,警报根本不起作用。
这是我的动态创建警报的回声语句
echo "<script>alert('Uploaded file was not in the correct format\n\nExample of the correct format:\nquestion1,answer1,answer2,answer3,answer4\n
question2,answer1,answer2,answer3,answer4\nquestion3,answer1,answer2,answer3,answer4')</script>";
我发现如果我将警报更改为此,它会完美运行:
echo "<script>alert('Uploaded file was not in the correct format')</script>";
我相信换行符有问题。
我将代码更改为此,但仍然没有运气:
echo "<script>alert('Uploaded file was not in the correct format\\nExample of the correct format:\\nquestion1,answer1,answer2,answer3,answer4\\n
question2,answer1,answer2,answer3,answer4\\nquestion3,answer1,answer2,answer3,answer4')</script>";
我收到以下错误:
SyntaxError: unterminated string literal
[Break On This Error]
alert('Uploaded file was not in the correct format\nExample of the
------^
createplay.php (line 1, col 6)
有人对为什么这不起作用有任何建议吗?在网上搜索了很多,找不到解决方案。
提前致谢!