Javascript 如何使用 PHP 弹出警告消息框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13851528/
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 pop an alert message box using PHP?
提问by adil
How to pop an alert message box using PHP?
如何使用 PHP 弹出警告消息框?
回答by Peter Gluck
You could use Javascript:
你可以使用Javascript:
// This is in the PHP file and sends a Javascript alert to the client
$message = "wrong answer";
echo "<script type='text/javascript'>alert('$message');</script>";
回答by Deepak Play
Create function for alert
创建警报功能
<?php
alert("Hello World");
function alert($msg) {
echo "<script type='text/javascript'>alert('$msg');</script>";
}
?>
回答by kmoney12
PHP renders HTML and Javascript to send to the client'sbrowser. PHP is a server-sidelanguage. This is what allows it do things like INSERT something into a database on the server.
PHP 呈现 HTML 和 Javascript 以发送到客户端的浏览器。PHP 是一种服务器端语言。这就是允许它执行诸如将某些内容插入服务器上的数据库之类的操作。
But an alert is rendered by the browser of the client. You would have to work through javascript to get an alert.
但是客户端的浏览器会呈现警报。您必须通过 javascript 来获取警报。
回答by Riccardo Volpe
I have done it this way:
我是这样做的:
<?php
$PHPtext = "Your PHP alert!";
?>
var JavaScriptAlert = <?php echo json_encode($PHPtext); ?>;
alert(JavaScriptAlert); // Your PHP alert!
回答by mrbengi
See this example :
看这个例子:
<?php
echo "<div id='div1'>text</div>"
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/jquery1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#div1').click(function () {
alert('I clicked');
});
});
</script>
</head>
<body>
</body>
</html>
回答by user1899745
Use jquery between the php command $alert
在 php 命令 $alert 之间使用 jquery
回答by Kamil Kie?czewski
This .php file content will generate valid htmlwith alert (you can even remove <?php...?>)
此 .php 文件内容将生成带有警报的有效 html(您甚至可以删除<?php...?>)
<!DOCTYPE html><html><title>p</title><body onload="alert('<?php echo 'Hi' ?>')">
回答by Ibrahim Hasanov
You can use DHP to do this. It is absolutely simple and it is fast than script.
Just write alert('something');It is not programing language it is something like a lit bit jquery. You need require dhp.php in the top and in the bottom require dhpjs.php.
For now it is not open source but when it is you can use it. It is our programing language ;)
您可以使用 DHP 来执行此操作。它绝对简单,而且比脚本快。只需编写alert('something');它不是编程语言,它类似于一个点亮的 jquery。您需要在顶部需要 dhp.php,在底部需要 dhpjs.php。目前它不是开源的,但是当它是你可以使用它。这是我们的编程语言 ;)

