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

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

WBOY
Release: 2016-06-13 11:55:55
Original
1198 people have browsed it

请问为什么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>";
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template