html生成注册与登录代码

以下是一个简单的HTML代码示例,用于生成注册和登录表单。这个示例使用了基本的HTML和CSS来创建两个表单:一个用于注册,另一个用于登录。

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册与登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }
        h2 {
            margin-bottom: 20px;
        }
        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        input[type="submit"] {
            width: 100%;
            padding: 10px;
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #218838;
        }
        .switch-form {
            margin-top: 20px;
        }
        .switch-form a {
            color: #007bff;
            text-decoration: none;
        }
        .switch-form a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>

<div class="container" id="login-container">
    <h2>登录</h2>
    <form id="login-form">
        <input type="text" placeholder="用户名" required>
        <input type="password" placeholder="密码" required>
        <input type="submit" value="登录">
    </form>
    <div class="switch-form">
        <p>还没有账号? <a href="#" onclick="switchToRegister()">注册</a></p>
    </div>
</div>

<div class="container" id="register-container" style="display: none;">
    <h2>注册</h2>
    <form id="register-form">
        <input type="text" placeholder="用户名" required>
        <input type="password" placeholder="密码" required>
        <input type="password" placeholder="确认密码" required>
        <input type="submit" value="注册">
    </form>
    <div class="switch-form">
        <p>已有账号? <a href="#" onclick="switchToLogin()">登录</a></p>
    </div>
</div>

<script>
    function switchToRegister() {
        document.getElementById('login-container').style.display = 'none';
        document.getElementById('register-container').style.display = 'block';
    }

    function switchToLogin() {
        document.getElementById('register-container').style.display = 'none';
        document.getElementById('login-container').style.display = 'block';
    }
</script>

</body>
</html>

代码说明:

  1. HTML结构

    • 有两个容器 #login-container#register-container,分别用于登录和注册表单。

    • 每个表单包含输入字段(用户名、密码等)和一个提交按钮。

  2. CSS样式

    • 使用了一些基本的样式来美化表单,使其居中显示,并添加了一些阴影和圆角效果。

    • 输入字段和按钮的样式也进行了简单的设计。

  3. JavaScript功能

    • 使用 switchToRegister()switchToLogin() 函数来切换显示登录和注册表单。

    • 通过 onclick 事件调用这些函数来切换表单的显示状态。

使用方法:

  • 将此代码保存为一个 .html 文件,然后在浏览器中打开即可看到效果。

  • 你可以根据需要进一步扩展和定制这个表单,例如添加表单验证、后端处理等。

这个示例是一个基础的实现,适合初学者理解HTML表单的基本结构和样式设计。

相关推荐
后台开发者Ethan2 小时前
setState组件更新
前端·javascript·react
蜡台3 小时前
uniapp vue2 转 vue3
前端·javascript·uni-app·vue3·vue2
用户059540174463 小时前
把前端内存泄漏排查从2小时压到5分钟,我们把它集成进了CI
前端·css
IMPYLH3 小时前
HTML 的 <dd> 元素
前端·html
WindfallSheng3 小时前
从Vibe Coding到Spec Coding:一套可落地的AI-SDD企业级研发实战工程
javascript·vue.js
Asize4 小时前
Agent 入门:从 LLM 与 Agent 的区别到 Function Calling
javascript·人工智能
山内桜良14 小时前
HarmonyOS中,html 与 ets 桥接沟通
华为·html·harmonyos
我有满天星辰4 小时前
Vue 指令完全指南:从 Vue 2 到 Vue 3 的演进与实战
前端·javascript·vue.js
小白学过的代码4 小时前
# flv.js / mpegts.js 播不了国标摄像头(H.265 + G.711A)?纯前端 Jessibuca 无后端方案(附完整代码)
前端·javascript·h.265
我有满天星辰7 小时前
Vue 3 响应式双雄:ref 与 reactive 完全指南
前端·javascript·vue.js