PHP 中的消息框没有 JS

Message box in PHP without JS

如何显示带有 PHP 代码的消息框?我看到了 this 答案,但我不想在 php 中使用 JS 代码。

像这样的东西应该可以完成工作:

<?php
if (isset($_POST['submit']))
{
    //data checks here...
    //database stuff here...      

    echo '<div class="msg">'
        .'YOUR MESSAGE IN HERE'
        .'</div>';
}
?>

<style>
    .msg {border:1px solid #bbb; padding:5px; margin:10px 0px; background:#eee;}
</style>

<form action="" method="post">
  Name:<input type="text" id="name" name="name"/>
  <input type="submit" value="submit" name="submit"/>
</form>

您提到的消息框是用 JS 或 HTML/CSS 创建的。由于您不想使用 JS,唯一的选择是返回包含所需框的 HTML。请记住,PHP 在服务器端执行,只是 returns 对每个请求的响应。返回响应后,PHP 不再执行。

有几个 UI 套件带有漂亮的盒子。 Bootstrap is one of the most popular and it's very easy to use. Check their getting started 页面,了解如何在您的布局中添加他们的 CSS。

我想我找到了你要找的东西。您需要在 div 中回显其中的一些文本,并在 div 中回显一个复选框。在您的 CSS 中,您可以检查复选框是否被选中并将其风格化以使其消失。该复选框将作为消息的关闭按钮。

在此处查看更多信息。Toggling class without using JavaScript