How to pop an alert message box using PHP?
问题:
回答1:
You could use 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>";
回答2:
Create function for alert
<?php
alert("Hello World");
function alert($msg) {
echo "<script type='text/javascript'>alert('$msg');</script>";
}
?>
回答3:
I have done it this way:
<?php
$PHPtext = "Your PHP alert!";
?>
var JavaScriptAlert = <?php echo json_encode($PHPtext); ?>;
alert(JavaScriptAlert); // Your PHP alert!
回答4:
PHP renders HTML and Javascript to send to the client's browser. PHP is a server-side language. This is what allows it do things like INSERT something into a database on the server.
But an alert is rendered by the browser of the client. You would have to work through javascript to get an alert.
回答5:
Use jquery between the php command $alert
回答6:
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>
回答7:
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 ;)