html登录注册页面代码怎么写

时间: 2023-10-10 19:08:00 浏览: 30
下面是一个简单的 HTML 登录注册页面代码示例: ```html <!DOCTYPE html> <html> <head> <title>Login/Register</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> form { display: flex; flex-direction: column; align-items: center; margin-top: 50px; } input[type=text], input[type=password] { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button { background-color: #4CAF50; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; } .container { padding: 16px; background-color: #f2f2f2; border-radius: 10px; box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2); } .error { color: red; font-size: 12px; margin-top: -10px; margin-bottom: 10px; } </style> </head> <body> <div class="container"> <h2>Login</h2> <form id="loginForm" action="#" method="post"> <label for="username">Username</label> <input type="text" id="username" name="username" required> <label for="password">Password</label> <input type="password" id="password" name="password" required> <button type="submit">Login</button> <p>Don't have an account? <a href="#" onclick="toggleForm()">Register here</a></p> </form> <form id="registerForm" action="#" method="post" style="display: none"> <h2>Register</h2> <label for="newUsername">Username</label> <input type="text" id="newUsername" name="newUsername" required> <label for="newPassword">Password</label> <input type="password" id="newPassword" name="newPassword" required> <label for="confirmPassword">Confirm Password</label> <input type="password" id="confirmPassword" name="confirmPassword" required> <button type="submit">Register</button> <p>Already have an account? <a href="#" onclick="toggleForm()">Login here</a></p> </form> <div id="errorMessage" class="error" style="display: none"></div> </div> <script> const loginForm = document.getElementById("loginForm"); const registerForm = document.getElementById("registerForm"); const errorMessage = document.getElementById("errorMessage"); function toggleForm() { loginForm.style.display = loginForm.style.display === "none" ? "block" : "none"; registerForm.style.display = registerForm.style.display === "none" ? "block" : "none"; errorMessage.style.display = "none"; } loginForm.addEventListener("submit", function(event) { event.preventDefault(); const username = document.getElementById("username").value; const password = document.getElementById("password").value; // TODO: check if the username and password are correct and logged the user in errorMessage.style.display = "none"; }); registerForm.addEventListener("submit", function(event) { event.preventDefault(); const newUsername = document.getElementById("newUsername").value; const newPassword = document.getElementById("newPassword").value; const confirmPassword = document.getElementById("confirmPassword").value; if (newPassword !== confirmPassword) { errorMessage.innerText = "Passwords do not match"; errorMessage.style.display = "block"; } else { // TODO: create a new user with the username and password and log them in errorMessage.style.display = "none"; } }); </script> </body> </html> ``` 该示例包括两个表单,一个用于登录,另一个用于注册。当用户单击“注册”链接时,将切换表单。表单使用了一些基本的 CSS 样式,来使其看起来更好看一些,并且包含了一些 JavaScript 代码来处理表单的提交和切换。请注意,此示例中的登录和注册功能仅为示例,需要根据实际情况进行修改。

相关推荐

最新推荐

recommend-type

概率论与数理统计试卷三套(含答案)

2020-2021年概率论与数理统计试卷
recommend-type

“人力资源+大数据+薪酬报告+涨薪调薪”

人力资源+大数据+薪酬报告+涨薪调薪,在学习、工作生活中,越来越多的事务都会使用到报告,通常情况下,报告的内容含量大、篇幅较长。那么什么样的薪酬报告才是有效的呢?以下是小编精心整理的调薪申请报告,欢迎大家分享。相信老板看到这样的报告,一定会考虑涨薪的哦。
recommend-type

伊坂幸太郎21册合集.mobi

伊坂幸太郎21册合集.mobi
recommend-type

dsdy-b4-v30003-1h.apk

dsdy-b4-v30003-1h.apk
recommend-type

Python实现基于Socket通信+PyQt5的仿QQ聊天系统项目源码(高分项目)

Python实现基于Socket通信+PyQt5的仿QQ聊天系统项目源码(高分项目)开发软件: Pycharm+ Python3.6数据库:mysql8.0 本软件基于python gui图形库pyqt5编写的仿qq,采用mysql数据库存储,socket通信(tcp协议)实现,支持多账号登录,注册,单人私聊,群聊,添加好友分组等功能。 Python实现基于Socket通信+PyQt5的仿QQ聊天系统项目源码(高分项目)客户端界面目录文件:pyqt5-qq,服务端目录文件:Tcpserver Python实现基于Socket通信+PyQt5的仿QQ聊天系统项目源码(高分项目)服务端目录结构: common:存放公共的工具类代码文件目录,主要是配置文件解析工具类,数据库操作工具类,本软件主要使用的是sqlalchemy orm数据库框架。 configfile:存放配置文件目录 dto:存放数据库表模型类代码文件 Python实现基于Socket通信+PyQt5的仿QQ聊天系统项目源码(高分项目)客户端目录结构: image,res:存放资源文件,其他文件:界面及逻辑实现源码
recommend-type

STC89C51 简单时钟

STC89C51 简单时钟,叫你从基础开始学习单片机,
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB归一化方法大比拼:5种方法,哪种最适合你的数据?

![MATLAB归一化方法大比拼:5种方法,哪种最适合你的数据?](https://www.finebi.com/wp-content/uploads/2019/11/FineBI%E8%A1%8C%E4%B8%9A%E9%A9%BE%E9%A9%B6%E8%88%B1-1024x510.png) # 1. MATLAB归一化概述 归一化是一种数据预处理技术,用于将数据缩放到特定范围内,从而消除不同特征之间的尺度差异。在MATLAB中,有各种归一化方法可用于不同类型的数据和应用程序。 归一化的主要目的是: - 提高模型的训练效率和准确性,通过消除特征之间的尺度差异,使模型能够更有效地学习
recommend-type

failed to register layer: ApplyLayer exit status 1 stdout: stderr: archive/tar: invalid tar header

很抱歉听到这个问题。这个错误通常是由于Docker镜像损坏或Docker存储库中缺少所需的图层引起的。您可以尝试以下几种方法来解决这个问题: 1. 清理Docker镜像和容器:使用命令“docker system prune”清理不再使用的Docker对象。 2. 检查Docker存储库:确保您正在使用可靠的Docker存储库,并检查是否存在所有必需的图层。 3. 重新下载Docker镜像:如果您确定问题是由于损坏的Docker镜像引起的,则可以尝试重新下载Docker镜像。 4. 更新Docker版本:如果您使用的是旧版Docker,则可能会出现此问题。尝试更新到最新版本的Docke
recommend-type

Linux系统常用操作命令大全手册

附件是Linux系统常用操作命令大全手册,是 markdown格式,其中覆盖了Linux系统管理、文件操作、网络配置等多个方面,都是日常工作中非常常用的命令,欢迎大家下载学习使用!