用html,css,js写一个登录页
时间: 2023-05-22 19:07:04 浏览: 41
好的,以下是一个用html,css,js写的登录页的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
<style>
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,.1);
width: 300px;
margin: 50px auto;
}
h2 {
font-size: 24px;
margin: 0 0 20px;
text-align: center;
}
label {
display: block;
margin: 0 0 10px;
color: #666;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin: 0 0 20px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
padding: 10px;
width: 100%;
font-size: 16px;
margin: 20px 0 0;
}
input[type="submit"]:hover {
background-color: #31842f;
}
</style>
</head>
<body>
<form>
<h2>用户登录</h2>
<label for="username">用户名</label>
<input type="text" id="username" name="username" required>
<label for="password">密码</label>
<input type="password" id="password" name="password" minlength="8" required>
<input type="submit" value="登录">
</form>
<script>
let form = document.querySelector('form');
form.addEventListener('submit', function(e) {
e.preventDefault();
let username = form.querySelector('#username').value;
let password = form.querySelector('#password').value;
console.log(`用户名:${username},密码:${password}`);
// 这里可以添加登录逻辑
});
</script>
</body>
</html>
```
希望对您有帮助!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)