今天开始写web项目,画了一下登录界面,借鉴了一下网上的资源。
<!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>
/* Flex布局实现垂直水平居中 */
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
font-family: 'Arial', sans-serif;
}
.login-container {
width: 350px;
padding: 40px;
background: white;
border-radius: 10px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
h2 {
text-align: center;
margin-bottom: 30px;
}
.input-group{
margin-bottom: 20px;
position: relative;
}
input {
width: 100%;
padding: 12px 15px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
transition: border 0.3s;
}
input:focus {
border-color: #4285f4;
outline: none;
box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}
label {
position: absolute;
left: 15px;
top: 12px;
color: #999;
transition: all 0.3s;
pointer-events: none;
}
input:focus + label,
input:not(:placeholder-shown) + label {
top: -10px;
left: 10px;
font-size: 12px;
background: white;
padding: 0 5px;
color: #4285f4;
}
button {
width: 100%;
padding: 12px;
background: #4285f4;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background 0.3s;
}
button:hover {
background: #3367d6;
}
.error-message {
color: #d32f2f;
font-size: 14px;
margin-top: 5px;
height: 20px;
}
</style>
</head>
<body>
<!-- 登录的容器 -->
<div class="login-container">
<h2>欢迎登录</h2>
<form action="" id="loginForm">
<div class="input-group">
<input type="text" id="username" autocomplete="off" placeholder=" ">
<label for="username"> 用户名</label>
<div class="error-message" id="username-error"></div>
</div>
<div class="input-group">
<input type="password" id="password" placeholder=" ">
<label for="password"> 密码</label>
<div class="error-message" id="password-error"></div>
</div>
<button typr="submit">登 录</button>
</form>
<script>
let lf = document.getElementById("loginForm");
lf.addEventListener("submit", async(e)=>{
//这个的意思就是在提交之前我检查一下你的格式是否正确
//相当于是正则表达式
e.preventDefault();// 防止表单提交
const username=document.getElementById("username").value.trim();
const password=document.getElementById("password").value;
if (!username){
document.getElementById("username-error").textContent="请输入用户名";
return;
}
if (!password){
document.getElementById("password-error").textContent="请输入密码";
return;
}
// 验证是否包含特殊字符
const regex = /[!@#$%^&*(),.?":{}|<>]/; // 定义特殊字符的正则表达式
if(!regex.test(username)){
document.getElementById("password-error").textContent='用户名至少包含一个特殊字符';
}
})
</script>
</div>
</body>
</html>
还写了类似于一个正则表达式的东西,密码必须带有特殊字符,否则提示错误
// 验证是否包含特殊字符
const regex = /[!@#$%^&*(),.?":{}|<>]/; // 定义特殊字符的正则表达式
if(!regex.test(username)){
document.getElementById("password-error").textContent='用户名至少包含一个特殊字符';
}
画了一个er图
用户有哪些属性
用户:ID、用户名、密码、性别、生日(吧龄)、头像、年龄、账号状态、个人简介、粉丝、关注、IP地址、最后IP地址、创建时间、评论
有些没有属性没有写到,到时候慢慢添加
还学了些建表的操作语句
接下来边学习双token边写