Pet*_*uck 252

你可以使用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>";
Run Code Online (Sandbox Code Playgroud)


Dee*_*lay 14

创建警报功能

<?php
alert("Hello World");

function alert($msg) {
    echo "<script type='text/javascript'>alert('$msg');</script>";
}
?>
Run Code Online (Sandbox Code Playgroud)


Ben*_*llo 5

您需要一些 JS,只需alert('Your message')在 PHP 代码中添加即可实现此目的。

请参阅下面的示例

     <?php 

//my other php code here
        
        function function_alert() { 
              
            // Display the alert box; note the Js tags within echo, it performs the magic
            echo "<script>alert('Your message Here');</script>"; 
        } 
        
        ?> 
Run Code Online (Sandbox Code Playgroud)

当您使用触发您的路径访问浏览器时function_alert,您将看到屏幕上显示带有消息的警报框。

了解更多信息,请访问https://www.geeksforgeeks.org/how-to-pop-an-alert-message-box-using-php/