在PHP中等效于Alert()和Prompt() [英] Equivalent of Alert() and Prompt() in PHP

查看:207
本文介绍了在PHP中等效于Alert()和Prompt()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中,我们有Alert()和Prompt(),它们为用户打开一个弹出框。

In JavaScript, we have Alert() and Prompt() which open up a popup box for the user.

PHP是否具有等效功能?
$ Get _ ['asdf'] 是获取用户输入的一种方法……还有其他方法吗?

Is there an equivalent for PHP? $Get_['asdf'] is one way to get user input... any others?

还有一个问题。是否必须始终一次执行PHP?还是就像JavaScript,它等待用户输入(例如弹出框),然后在那之后执行其余代码。

Also, one more question. Is it a requirement that PHP always be executed all at once? Or can it be like JavaScript, where it waits for the user input (e.g. popup box), then executes the rest of the code after that.

推荐答案

PHP是服务器端语言,它无法在客户端发出警报消息。但是您可以在php中使用javascript来发出警报。

PHP is a server side language, it can't do alert messages on the client side. But you can use javascript within the php to do the alert.

<script type="text/javascript">
window.alert("Hi There, I am the Alert Box!")
</script>

对于提示,您可以执行以下操作-

For Prompt you can do something like this -

<?php

    //prompt function
    function prompt($prompt_msg){
        echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");

        $answer = "<script type='text/javascript'> document.write(answer); </script>";
        return($answer);
    }

    //program
    $prompt_msg = "Please type your name.";
    $name = prompt($prompt_msg);

    $output_msg = "Hello there ".$name."!";
    echo($output_msg);

?>

这篇关于在PHP中等效于Alert()和Prompt()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆