PHP

如何在php中实现确认对话框

小樊
81
2024-09-26 23:58:01
栏目: 编程语言

在 PHP 中,要实现确认对话框,通常需要结合 HTML、JavaScript 和 CSS 来完成

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PHP Confirm Dialog Example</title>
    <style>
        .dialog {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.5);
        }
        .dialog-content {
            background-color: #fff;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 50%;
        }
    </style>
</head>
<body>
    <button onclick="showConfirmDialog()">Click me to show a confirm dialog</button>

    <div id="confirmDialog" class="dialog">
        <div class="dialog-content">
            <p>Are you sure you want to proceed?</p>
            <button onclick="confirmAction(true)">Yes</button>
            <button onclick="confirmAction(false)">No</button>
        </div>
    </div>

    <script>
        function showConfirmDialog() {
            document.getElementById('confirmDialog').style.display = 'block';
        }

        function confirmAction(confirmed) {
            if (confirmed) {
                alert('You clicked Yes!');
            } else {
                alert('You clicked No!');
            }
            document.getElementById('confirmDialog').style.display = 'none';
        }
    </script>
</body>
</html>

在这个示例中,我们创建了一个简单的 HTML 页面,其中包含一个按钮和一个隐藏的确认对话框。当用户点击按钮时,showConfirmDialog() JavaScript 函数会被调用,显示确认对话框。用户可以通过点击“Yes”或“No”按钮来关闭对话框,并触发 confirmAction() 函数。这个函数会根据用户的操作执行相应的操作,例如弹出一个提示框显示用户的选择。

0
看了该问题的人还看了