帮我使用html写一个登录界面实现界面登陆方式之间切换
时间: 2024-02-26 22:59:30 浏览: 28
好的,以下是一个简单的登录界面,包括切换不同的登录方式:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<style type="text/css">
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.container {
margin: 50px auto;
background-color: #fff;
width: 400px;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
h1 {
text-align: center;
margin-top: 0;
}
form {
margin-top: 20px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
box-sizing: border-box;
margin-bottom: 20px;
font-size: 16px;
}
button[type="submit"] {
background-color: #0066cc;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
width: 100%;
}
.login-type {
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.login-type button {
margin-right: 10px;
background-color: transparent;
color: #0066cc;
border: none;
cursor: pointer;
font-size: 14px;
}
.login-type button.active {
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Login</h1>
<form>
<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>
</form>
<div class="login-type">
<button class="active" onclick="showLoginForm()">Email</button>
<button onclick="showSmsForm()">SMS</button>
</div>
</div>
<script type="text/javascript">
function showLoginForm() {
document.getElementById("username").placeholder = "Email";
document.getElementById("password").placeholder = "Password";
document.querySelectorAll(".login-type button").forEach(button => {
button.classList.remove("active");
});
document.querySelector(".login-type button:first-child").classList.add("active");
}
function showSmsForm() {
document.getElementById("username").placeholder = "Phone number";
document.getElementById("password").placeholder = "SMS code";
document.querySelectorAll(".login-type button").forEach(button => {
button.classList.remove("active");
});
document.querySelector(".login-type button:last-child").classList.add("active");
}
</script>
</body>
</html>
```
这个登录界面包括一个用户名和密码的登录表单,以及两个切换登录方式的按钮。通过点击不同的按钮,表单的输入框的提示文本会发生相应的变化。