Javascript 如何在 PHP 中显示警告框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13837375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show an alert box in PHP?
提问by prakash_d22
I want to display an alert box showing a message with PHP.
我想显示一个警告框,显示带有 PHP 的消息。
Here is my PHP code:
这是我的PHP代码:
<?php
header("Location:form.php");
echo '<script language="javascript">';
echo 'alert(message successfully sent)'; //not showing an alert box.
echo '</script>';
exit;
?>
But it is not working.
但它不起作用。
回答by Yogesh Suthar
use this code
使用此代码
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
The problem was:
问题是:
- you missed
" - It should be
alertnotalery
- 你错过了
" - 应该
alert不是alery
回答by maqs
Try this:
尝试这个:
Define a funciton:
定义一个函数:
<?php
function phpAlert($msg) {
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}
?>
Call it like this:
像这样调用它:
<?php phpAlert( "Hello world!\n\nPHP has got an Alert Box" ); ?>
回答by Muhammad Talha Akbar
There is a syntax error (typo):
有一个语法错误(错字):
It's alertnot alery.
这是alert不是alery。
回答by ashiina
echo '<script language="javascript>';
Seems like a simple typo. You're missing a double-quote.
似乎是一个简单的错字。你缺少一个双引号。
echo '<script language="javascript">';
This should do.
这个应该可以。
回答by silly
change your output from
改变你的输出
echo '<script language="javascript>';
to
到
echo '<script type="text/javascript">';
you forgot double quotes... and use the type tag
你忘了双引号......并使用类型标签
回答by Akhilraj N S
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
回答by CE_REAL
When I just run this as a page
当我把它作为一个页面运行时
<?php
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
exit;
it works fine.
它工作正常。
What version of PHP are you running?
您运行的是哪个版本的 PHP?
Could you try echoing something else after: $testObject->split_for_sms($Chat);
您能否尝试在以下之后回显其他内容: $testObject->split_for_sms($Chat);
Maybe it doesn't get to that part of the code? You could also try these with the other function calls to check where your program stops/is getting to.
也许它没有到达代码的那部分?您还可以尝试使用其他函数调用来检查程序停止/到达的位置。
Hope you get a bit further with this.
希望你能更进一步。
回答by Prakash Madhak
echo "<script>alert('same message');</script>";
This may help.
这可能会有所帮助。
回答by faid
I don't know about php but i belive the problem is from this :
我不知道 php,但我相信问题出在这里:
echo '<script language="javascript>';
echo 'alery("message successfully sent")';
echo '</script>';
Try to change this with :
尝试改变这一点:
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';

