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

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

WBOY
WBOYOriginal
2016-06-23 13:58:071377browse

(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>";

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


谢谢,你的回答很正确,很仔细。但是修改$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>";

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

$serial_number = 'wang gang';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
Previous article:PHP语句问题Next article:PHP链接MySQL问题。新手求助