基本上,我試圖通過PHP調用Javascript警報。雖然,警報根本不起作用。爲什麼我的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)
有沒有人有這是爲什麼不工作有什麼建議?在線搜索範圍很廣,找不到解決方案。
在此先感謝!
嘗試使用'\\ n'而不是'\ n' – Pointy
爲什麼你看着你的PHP並聲明你的JavaScript不工作?看看生成的JavaScript! – Quentin
如果交換引用樣式,會發生什麼情況? 'echo'';' – j08691