HTML创建对话框

发布于:2023-10-25 ⋅ 阅读:(77) ⋅ 点赞:(0)

<!DOCTYPE html>
<html>
<head>
  <title>对话框系统</title>
  <style>
    .dialog {
      display: none;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 300px;
      padding: 20px;
      background-color: #f1f1f1;
      border: 1px solid #ccc;
      border-radius: 5px;
    }
  </style>
</head>
<body>
  <button οnclick="openDialog('message')">打开对话框</button>
  <div id="message" class="dialog">
    <h2>对话框标题</h2>
    <p>这里是对话框的内容。</p>
    <button οnclick="closeDialog('message')">关闭</button>
  </div>
  <script>
    function openDialog(id) {
      var dialog = document.getElementById(id);
      dialog.style.display = 'block';
    }
    function closeDialog(id) {
      var dialog = document.getElementById(id);
      dialog.style.display = 'none';
    }
  </script>
</body>
</html>


网站公告

今日签到

点亮在社区的每一天
去签到