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

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

WBOY
Release: 2016-06-23 13:58:07
Original
1389 people have browsed it

(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)无结果,没有提示错误
请问,原因是什么,怎么解决?


回复讨论(解决方案)

php中连接字符串用".",不是"+"

呵呵,我看错了,你把alert("我是"+a+“朋友”)中的”“改成‘’

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

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


谢谢,你的回答很正确,很仔细。但是修改$serial_number=‘wang gang’;后就不弹框了,请问该如何解决呢?

呵呵,我看错了,你把alert("我是"+a+“朋友”)中的”“改成‘’


但是修改$serial_number=‘wang gang’;后就不弹框了,请问该如何解决呢?

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

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

$serial_number = 'wang gang';echo "<script type='text/javascript'>var a='$serial_number';alert('我是' + a + '朋友');</script>";
Copy after login
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