用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>
相关推荐
这是个栗子1 分钟前
前端开发中的常用工具函数(六)
javascript·every
码云数智-园园1 分钟前
从输入 URL 到页面展示:一场精密的互联网交响乐
前端
智算菩萨12 分钟前
GPT-5.4 Pro与Thinking模型全面研究报告
人工智能·gpt·ai·chatgpt·ai-native
秋水无痕27 分钟前
# 手把手教你从零搭建 AI 对话系统 - React + Spring Boot 实战(一)
前端·后端
高桥凉介发量惊人29 分钟前
基础与工程篇-多环境配置(dev/test/prod)与打包策略
前端
墨鱼笔记30 分钟前
前端必看:Vite.config.js 最全配置指南 + 实战案例
前端·vite
kyriewen31 分钟前
异步编程:从“回调地狱”到“async/await”的救赎之路
前端·javascript·面试
前端Hardy34 分钟前
别再手动写 loading 了!封装一个自动防重提交的 Hook
前端·javascript·vue.js
前端Hardy35 分钟前
前端如何实现“无感刷新”Token?90% 的人都做错了
前端·javascript·vue.js
秋水无痕36 分钟前
# 手把手教你从零搭建 AI 对话系统 - React + Spring Boot 实战(二)
前端·后端·面试