html css js登录注册界面代码
时间: 2023-08-31 09:21:19 浏览: 75
### 回答1:
<!DOCTYPE html>
<html>
<head>
<title>Login and Registration Form</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body{
background-color: #f1f1f1;
font-family: Arial, sans-serif;
}
h2{
text-align: center;
color: #333;
}
.container{
max-width: 500px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
form{
display: flex;
flex-direction: column;
align-items: center;
}
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: #fff;
padding: 12px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}
button:hover{
background-color: #45a049;
}
.error{
color: red;
font-size: 12px;
margin-top: 5px;
margin-bottom: 0;
}
.success{
color: green;
font-size: 12px;
margin-top: 5px;
margin-bottom: 0;
}
.switch{
text-align: center;
margin-top: 20px;
}
.switch a{
color: #4CAF50;
text-decoration: none;
}
.switch a:hover{
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h2>Login and Registration Form</h2>
<div id="login">
<form action="#" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Enter your username" required>
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Enter your password" required>
<button type="submit">Login</button>
<p class="switch">Don't have an account? <a href="#" onclick="switchForm()">Register here.</a></p>
</form>
</div>
<div id="register" style="display: none;">
<form action="#" method="post">
<label for="fullname">Full Name</label>
<input type="text" id="fullname" name="fullname" placeholder="Enter your full name" required>
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="Enter your email" required>
<label for="newusername">Username</label>
<input type="text" id="newusername" name="newusername" placeholder="Enter a username" required>
<label for="newpassword">Password</label>
<input type="password" id="newpassword" name="newpassword" placeholder="Enter a password" required>
<button type="submit">Register</button>
<p class="switch">Already have an account? <a href="#" onclick="switchForm()">Login here.</a></p>
</form>
</div>
<div id="message"></div>
</div>
<script>
function switchForm(){
var loginForm = document.getElementById("login");
var registerForm = document.getElementById("register");
if(loginForm.style.display === "none"){
loginForm.style.display = "block";
registerForm.style.display = "none";
} else{
loginForm.style.display = "none";
registerForm.style.display = "block";
}
document.getElementById("message").innerHTML = "";
}
</script>
</body>
</html>
### 回答2:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>登录注册界面</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div class="container">
<form id="login-form" class="form" action="login.php" method="post">
<h2>登录</h2>
<input type="text" placeholder="用户名" name="username" required>
<input type="password" placeholder="密码" name="password" required>
<button type="submit">登录</button>
</form>
<form id="register-form" class="form" action="register.php" method="post">
<h2>注册</h2>
<input type="text" placeholder="用户名" name="username" required>
<input type="password" placeholder="密码" name="password" required>
<button type="submit">注册</button>
</form>
</div>
</body>
</html>
```
CSS代码(style.css):
```css
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.form {
width: 300px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
h2 {
text-align: center;
}
input {
width: 100%;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
width: 100%;
padding: 10px;
background-color: #337ab7;
color: #fff;
border: none;
border-radius: 3px;
}
```
JavaScript代码(script.js):
```javascript
// 在此添加任何需要的JavaScript代码,例如表单验证等
```
以上是一个简单的登录注册界面的HTML、CSS和JavaScript代码。HTML部分包含两个表单,用于登录和注册,分别包括用户名和密码的输入框以及提交按钮。CSS部分用于设置界面的样式,包括容器的布局、表单的样式等。JavaScript部分可以用于添加表单验证等额外功能。
请注意,以上代码仅为示例,可能需要根据具体需求进行修改和完善。
### 回答3:
以下是一个简单的HTML、CSS和JavaScript的登录注册界面代码:
HTML部分:
```html
<!DOCTYPE html>
<html>
<head>
<title>登录注册界面</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="login">
<h2>登录</h2>
<form>
<input type="text" placeholder="用户名" required>
<input type="password" placeholder="密码" required>
<button type="submit">登录</button>
</form>
</div>
<div id="register">
<h2>注册</h2>
<form>
<input type="text" placeholder="用户名" required>
<input type="password" placeholder="密码" required>
<input type="password" placeholder="确认密码" required>
<button type="submit">注册</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
```
CSS部分(style.css):
```css
body {
font-family: Arial, sans-serif;
background-color: #f1f3f5;
}
#login, #register {
background-color: white;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 300px;
margin: 0 auto;
margin-top: 100px;
}
h2 {
margin-bottom: 20px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
```
JavaScript部分(script.js):
```javascript
// 登录表单和注册表单的显示切换
document.getElementById("register").style.display = "none";
document.getElementById("login-link").addEventListener("click", function(){
document.getElementById("login").style.display = "block";
document.getElementById("register").style.display = "none";
});
document.getElementById("register-link").addEventListener("click", function(){
document.getElementById("login").style.display = "none";
document.getElementById("register").style.display = "block";
});
```
以上代码创建了一个简单的登录注册界面。其中包含一个登录的字段和一个注册的字段。使用HTML创建了表单,CSS样式美化页面布局,JavaScript代码实现了登录表单和注册表单的显示切换功能。用户可以在登录表单输入用户名和密码进行登录,也可以在注册表单输入用户名和密码进行注册。