我正在尝试将字符串变量通过名为alertText的php函数的参数传递给名为alert的javascript函数,以将消息提示给屏幕,但是由于某种原因它不接受php变量,因此没有任何提示屏幕。请看一下:
testing.php
function alertText($text) {
echo "
<script>
alert($text);
</script>
";
}
alertText("Hello");
?>
您需要单引号$ text变量,因为JavaScript无法将该变量识别为字符串。
<?php
function alertText($text) {
echo "<script>alert('$text');</script>";
}
alertText("Hello");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句