我可以使用php在JavaScript中弹出警报吗 [英] Can I pop up alert in javascript using php
问题描述
我想使用PHP触发JavaScript警报. 有可能
I want to trigger javascript alert using PHP. Is it possible
我想在头部分使用它,以便在加载时显示它.
I want to use it in head section, for displaying it at load time.
<head>
<?php
$valid="valid";
if(!isset($valid))
echo "<script type=\"text/javascript\"> alert('Hi');</script>";
?>
</head>
编辑
我想在检查会话是否存在后在加载时显示javascript alert()
i want to display javascript alert() at load time after checking existance of session
推荐答案
当然可以.
您要做的只是输出JavaScript,都是一样的事情.
All you are doing is outputting JavaScript, it's all the same thing.
唯一的问题是您要嵌套<script>
标记,这是HTML错误,因此请删除echo
字符串中的标记.
The only issue is that you are nesting <script>
tags, which is an HTML error, so get rid of the tags in the echo
string.
<script type="text/javascript">
<?php
$valid="valid";
if(!isset($valid))
echo "alert('Hi');";
?>
</script>
顺便说一句,我确定您已经知道,此特定代码将始终回显"alert('Hi');"
By the way, as i'm sure you already know, this specific code will ALWAYS echo the "alert('Hi');"
这篇关于我可以使用php在JavaScript中弹出警报吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!