Home >Backend Development >PHP Tutorial >请教为什么javascript不能弹出提示框,内容如下

请教为什么javascript不能弹出提示框,内容如下

WBOY
WBOYOriginal
2016-06-13 11:55:551206browse

请问为什么javascript不能弹出提示框,内容如下
(1)
$serial_number=1;
echo "<script>var a=$serial_number;alert(a);</script>";
?>
(2)
$serial_number=1;
echo "<script>var a=$serial_number;alert("我是"+a+“朋友”);</script>";
?>

(1)弹框输出:1
(2)无结果,没有提示错误
请问,原因是什么,怎么解决?
------解决方案--------------------
呵呵,我看错了,你把alert("我是"+a+“朋友”)中的”“改成‘’
------解决方案--------------------

echo "<script type='text/javascript'>var a=$serial_number;alert(\"我是\"+a+\"朋友\");</script>";

------解决方案--------------------
$serial_number = 'wang gang';<br />echo "<script type='text/javascript'>var a='$serial_number';alert('我是' + a + '朋友');</script>";

字符串常量在 js 中同样是要用引号括起的,否则视为变量

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn