Php 为什么不显示我的Javascript警报?
基本上,我试图通过PHP调用Javascript警报。尽管如此,警报根本不起作用 这是动态创建警报的echo语句Php 为什么不显示我的Javascript警报?,php,javascript,alert,Php,Javascript,Alert,基本上,我试图通过PHP调用Javascript警报。尽管如此,警报根本不起作用 这是动态创建警报的echo语句 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\n
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>";
有没有人对为什么这不起作用有什么建议?在网上到处搜索,找不到解决方案
提前谢谢 您的
\n
字符被PHP替换为文字换行符
字符串文字中的Am unescaped文字换行符在JavaScript中是一个错误
使用
\\n
将换行转义序列发送到JavaScript。您的\n
字符将被PHP替换为文字换行符
字符串文字中的Am unescaped文字换行符在JavaScript中是一个错误
使用
\\n
将换行转义序列发送到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\\n\\nExample of the correct format:\\nquestion1,answer1,answer2,answer3,answer4\\n
question2,answer1,answer2,answer3,answer4\\nquestion3,answer1,answer2,answer3,answer4')</script>";
?>
若要添加到昆汀的答案中,切换单引号和双引号是否也可以解决问题?若要添加到昆汀的答案中,切换单引号和双引号是否也可以解决问题?在\n和下一个字符之间留出一个空格,这样就可以了。我在我的系统上为您的代码尝试了这一点,它起作用了在\n和下一个字符之间加一个空格,它就会起作用。我在我的系统上为您的代码尝试了这一点,它起了作用尝试使用\\n
而不是\n
为什么您查看PHP并声明JavaScript不起作用?看看生成的JavaScript!如果交换报价样式,会发生什么情况<代码>echo'警报(“上传的文件格式不正确\n\n正确格式的示例:\nquestion1、answer1、answer2、answer3、answer4\n问题2、answer1、answer2、answer3、answer4\nquestion3、answer1、answer2、answer3、answer4”)
尝试使用\\n
而不是\n
为什么查看PHP并声明JavaScript不工作?看看生成的JavaScript!如果交换报价样式,会发生什么情况<代码>echo'警报(“上传的文件格式不正确\n\n正确格式的示例:\nquestion1、answer1、answer2、answer3、answer4\n问题2、answer1、answer2、answer3、answer4\nquestion3、answer1、answer2、answer3、answer4”)代码>我将我的echo
更改为此,但仍然拒绝工作echo“警报(\\n上传的文件格式不正确\\正确格式的示例:\\nquestion1、answer1、answer2、answer3、answer4\\n问题2、answer1、answer2、answer3、answer4\\nquestion3、answer1、answer2、answer3、answer4”)代码>生成的JS看起来像什么?JS控制台怎么说?使用了你的解决方案,并像其他人所说的那样切换了引用。非常好,谢谢。我将我的echo
更改为此,但仍然拒绝工作echo“警报(\\n上传的文件格式不正确\\正确格式的示例:\\n提问1,回答1,回答2,回答3,回答4\\n问题2,回答1,回答2,回答3,回答4\\n提问3,回答1,回答2,回答4')代码>生成的JS看起来像什么?JS控制台怎么说?使用了你的解决方案,并像其他人所说的那样切换了引用。非常好用,谢谢。很高兴能帮上忙,实际上我只是试了一下,但对我不起作用!这也是双重逃跑吗?很高兴能帮上忙,我实际上只是尝试了一下,但它对我不起作用!这也是双重逃跑吗?
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)
<?
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>";
?>