用gpt写的登录页面

html 复制代码
<!DOCTYPE html>
<html>

<head>
  <title>登录页面</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      padding: 0;
    }

    .container {
      max-width: 400px;
      margin: 0 auto;
      padding: 20px;
      background-color: #fff;
      border-radius: 5px;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
      margin-top: 100px;
    }

    h1 {
      text-align: center;
    }

    .form-group {
      margin-bottom: 20px;
    }

    label {
      display: block;
      margin-bottom: 5px;
    }

    input[type="text"],
    input[type="password"] {
      width: 100%;
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
    }

    button {
      display: block;
      width: 100%;
      padding: 10px;
      background-color: #4caf50;
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }

    button:hover {
      background-color: #45a049;
    }
  </style>
</head>

<body>
  <div class="container">
    <h1>登录</h1>
    <form id="loginForm">
      <div class="form-group">
        <label for="username">用户名:</label>
        <input type="text" id="username" placeholder="请输入用户名">
      </div>
      <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" id="password" placeholder="请输入密码">
      </div>
      <button type="submit">登录</button>
    </form>
    <div style="text-align: center; margin-top: 20px;">
      <span>还没有账号?</span>
      <button id="registerButton">注册</button>
    </div>
  </div>

  <script>
    // 获取表单和输入字段的引用
    const form = document.getElementById("loginForm");
    const usernameInput = document.getElementById("username");
    const passwordInput = document.getElementById("password");
    const registerButton = document.getElementById("registerButton");

    // 表单提交事件处理程序
    form.addEventListener("submit", function (event) {
      event.preventDefault(); // 阻止表单默认提交行为

      // 获取输入字段的值
      const username = usernameInput.value;
      const password = passwordInput.value;

      // 进行验证,这里只是简单示例

      // 登录成功,跳转到首页
      window.location.href = "index.html";

    });

    // 注册按钮点击事件处理程序
    registerButton.addEventListener("click", function(event) {
      window.location.href = "register.html";
    });
  </script>
</body>

</html>
相关推荐
九九落16 分钟前
前端获取经纬度完全指南:从Geolocation API到地图集成
前端·获取经纬度
来恩100330 分钟前
jQuery选择器
前端·javascript·jquery
前端繁华如梦32 分钟前
树上挂苹果还是挂玻璃球?Three.js 程序化果实的完整实现指南
前端·javascript
墨痕诉清风39 分钟前
Web浏览器客户端检测网站网络健康(代码)
前端·网络·测试工具
IMPYLH41 分钟前
Linux 的 wc 命令
linux·运维·服务器·前端·bash
happybasic1 小时前
Python库升级标准流程~
linux·前端·python
川冰ICE1 小时前
前端工程化深度实战:从Webpack5到Vite5的构建工具演进与选型决策
前端
CDwenhuohuo1 小时前
优惠券组件直接用 uview plus
前端·javascript·vue.js
用户74090472362751 小时前
我用 curl 排查了一次 OpenAI-compatible API 连接失败:401、403、404 分别怎么定位
前端
kft13141 小时前
XSS深度剖析:从弹窗到持久化窃取Cookie
前端·web安全·xss·安全测试