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表单的基本结构和样式设计。

相关推荐
xuankuxiaoyao5 小时前
Vue.js实践-组件基础下
前端·javascript·vue.js
小白学大数据5 小时前
JS 混淆加密下的 Python 爬虫解决方案
javascript·爬虫·python
大家的林语冰6 小时前
前端周刊:axios 疑遭朝鲜黑客“钓鱼“;CSS 新函数上线;npm 上线深色主题;Oxlint 兼容表;ESLint 支持 Temporal......
前端·javascript·css
竹林8188 小时前
用ethers.js连接MetaMask实现Web3钱包登录:从踩坑到稳定运行的完整记录
前端·javascript
心连欣8 小时前
从零开始,学习所有指令!
前端·javascript·vue.js
openKaka_10 小时前
从 scheduleUpdateOnFiber 到 Root 微任务调度:React 如何把更新交给调度系统
开发语言·前端·javascript
LIO10 小时前
前端响应式通用 CSS(Flex 为主,含主色调)
前端·css
前进的李工10 小时前
智能Agent实战指南:记忆组件嵌入技巧(记忆)
开发语言·前端·javascript·python·langchain·agent
IOT.FIVE.NO.111 小时前
Codex Skill 内部结构解析:从 SKILL.md 到 scripts、references、assets
前端·javascript·人工智能·笔记·html