1、要求:点击注册后跳转至注册界面
(1)使用正则表达式验证邮箱
(2)密码长度至少为6位且为字母与数字的组合
登录界面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
width: 100%;
overflow: hidden;
margin: 0;
padding: 0;
background: url(img/1.jpg) no-repeat 0px 0px;
background-repeat: no-repeat;
background-size: 100% 100%;
-moz-background-size: 100% 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
background-image: url("背景4.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
}
#loginDiv {
width: 400px;
display: inline-block;
justify-content: center;
align-items: center;
height: 650px;
border-radius: 5px;
}
p,
.sexDiv {
margin-top: 10px;
margin-left: 20px;
color: azure;
}
.sexDiv>input,
.hobby>input {
width: 30px;
height: 17px;
}
input,
select {
margin-left: 15px;
border-radius: 5px;
border-style: hidden;
height: 30px;
width: 140px;
background-color: rgba(216, 191, 216, 0.5);
outline: none;
color: #f0edf3;
padding-left: 10px;
}
.button {
border-color: cornsilk;
background-color: rgba(100, 149, 237, .7);
color: aliceblue;
border-style: hidden;
border-radius: 5px;
width: 100px;
height: 31px;
font-size: 16px;
}
.introduce {
margin-left: 110px;
}
.introduce>textarea {
background-color: rgba(216, 191, 216, 0.5);
border-style: hidden;
outline: none;
border-radius: 5px;
}
h1 {
text-align: center;
margin-bottom: 20px;
margin-top: 20px;
color: #f0edf3;
}
b {
margin-left: 50px;
color: #FFEB3B;
font-size: 10px;
font-weight: initial;
}
</style>
</head>
<body>
<div style="width: 50%; height: 100%; position: relative;">
<div id="loginDiv">
<form action="#">
<h1>立即注册</h1>
<p>
邮件:
<input id="email" type="email" placeholder="请输入邮箱" required>
<label id="emil_trip"></label>
</p>
<p>用户名:<input id="userNname" type="text" placeholder="用户名不能超过5位"></p>
<p>
头像:
<input type="file">
</p>
<div class="sexDiv">
性别:
<input class="userSex" name="sex" value="boy" type="radio">男
<input class="userSex" name="sex" value="girl" type="radio">女
</div>
<p>密码:<input id="password" type="password" placeholder="密码长度至少为6位,且为数字字母组合" ></p>
<p>确认密码:<input id="surePassword" type="password" placeholder="两次输入的密码需一致" ></label></p>
<p style="text-align: left">
<input type="submit" class="button" onclick="checkForm()" value="注册">
</p>
</form>
</div>
<div style="width: 400px; height: 700px; display: inline-block; position: absolute; background-image: url(背景5.jpg);">
<br>
<br>
<br>
<h3 style="color: rgb(250, 242, 242); text-align: center;">已有账号?</h3> <br>
<h5 style="color:rgb(255, 254, 254); text-align: center;">有账号就登陆吧!好久不见了!</h5>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div style="text-align: center;">
<input type="button" onclick='location.href=("登录.html")' value="登陆">
</div>
</div>
</div>
</body>
<script type="text/javascript">
function checkForm() {
//获取用户名输入项
var userNname = document.getElementById("userNname");
var uName = userNname.value;
if (uName.length < 1 || uName.length > 5) {
alert("用户名长度为1-5位!!");
return false;
}
//密码长度大于6 和确认必须一致
var password = document.getElementById("password");
var userPass = password.value;
if (userPass.length < 6) {
alert("密码要>6位!!");
return false;
} else {
// 此处添加一个密码格式校验
var reg = new RegExp(/^[A-Za-z0-9]+$/);
if (!reg.test(str)) {
alert("密码要包含数字字母!!");
return false;
}
}
//获取确认密码框的值 var
var surePassword = document.getElementById("surePassword");
var surePass = surePassword.value;
if (userPass != surePass) {
alert("两次密码不一致!!");
return false;
}
//校验邮箱:/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/
var inputEmail = document.getElementById("email");
var uEmail = inputEmail.value;
if (!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(uEmail)) {
alert("邮箱不合法!!");
return false;
}
return true;
}
</script>
</html>
2.要求:
(1)使用正则表达式验证邮箱
(2)用户名长度不能超过五位
(3)密码长度至少为6位且为字母与数字的组合
(4) 两次密码输入须一致
代码:注册界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
html{
height: 100%;
width: 100%;
overflow: hidden;
margin: 0;
padding: 0;
background: url("背景2.jpg") no-repeat 0px 0px;
background-repeat: no-repeat;
background-size: 100% 100%;
-moz-background-size: 100% 100%;
}
#box1{
width: 500px;
height: 400px;
margin: auto;
padding:50px 20px 20px 20px ;
background-color: rgb(248, 247, 246);
opacity: 0.8;
}
#radio {
width: 500px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
height: 400px;
background-color: rgba(142, 166, 221, 0.3);
box-shadow: 7px 7px 17px rgba(106, 130, 179, 0.5);
border-radius: 1000px;
animation:turn 1s linear;
}
@keyframes turn{
0%{-webkit-transform:perspective(400px) rotateY(180deg);}
100%{-webkit-transform:perspective(400px) rotateY(0deg);}
}
input {
margin-left: 15px;
border-radius: 5px;
border-style: hidden;
height: 30px;
width: 140px;
background-color: rgb(252, 252, 252);
outline: none;
color: #f0edf3;
padding-left: 10px;
}
.button {
border-color: rgb(241, 241, 241);
background-color: rgba(100, 149, 237, .7);
color: aliceblue;
border-style: hidden;
border-radius: 50px;
width: 100px;
height: 31px;
font-size: 16px;
}
</style>
</head>
<body>
<div id="box1">
<div id="radio">
<form action="#" id="form">
<h1 style="text-align: center;color:balck;">立即登录</h1>
<p> 邮箱: <input id="email" type="text"><label id="name_trip"></label></p>
<p> 密码:<input id="password" type="password"><label id="password_trip"></label></p>
</br>
<a href="#" id="a">忘记密码?</a>
</br></br>
<div style="text-align: center;margin-top: 30px;">
<input type="submit" class="button" value="登录" onclick="check()">
<input type="button" class="button" onclick='location.href=("register.html")' value="注册">
</div>
</div>
</form>
</div>
</div>
</body>
<script language="javascript" type="text/javascript">
document.getElementById("b2").onclick = function click(){
window.location.href="register.html";
}
document.getElementById("a").onclick = function click(){
window.location.href="register.html";
}
function check() {
var inputEmail = document.getElementById("email");
// 获取输入内容
var uEmail = inputEmail.value;
// 检测邮箱格式
if (!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(uEmail)) {
alert("邮箱不合法");
return false;
}
//获取用户名输入项
var userPwd = document.getElementById("password");
var uPWD = userPwd.value;
if (uPWD.length < 6 || uPWD.length >= 15) {
alert("密码长度需要大于6位小于15位");
return false;
}
// 内容判断
var reg = new RegExp(/^[A-Za-z0-9]+$/);
if (!reg.test(uPWD)) {
alert("密码要包含数字字母!!");
return false;
}
window.open("photo.html");
}
</script>
</html>
3.登录成功后跳转至照片墙
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#div1 {
width: 100%;
height: 50px;
background: rgba(124, 58, 58, 0.966);
}
#div2 {
background-image: url(1.jpg);
position:fixed;
top: 0;
left: 0;
width:100%;
height:100%;
min-width: 1000px;
z-index:-10;
zoom: 1;
background-color: #fff;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-position: center 0;
}
#photo_box{
width: 280px;
height: 400px;
position: fixed;
left: 0;
right: 0;
top:0;
bottom: 0;
margin: 200px auto;
transform-style: preserve-3d;
transform: rotateX(-5deg) rotateY(0deg);
animation: run 30s linear infinite;
}
#photo_box img{
width: 250px;
height: 350px;
border: 5px solid #ccc;
border-radius: 5px;
position: absolute;
left: 0;
top: 0;
}
#photo_box img:nth-child(1){
transform: rotateY(0deg) translateZ(500px);
}
#photo_box img:nth-child(2){
transform: rotateY(36deg) translateZ(500px);
}
#photo_box img:nth-child(3){
transform: rotateY(72deg) translateZ(500px);
}
#photo_box img:nth-child(4){
transform: rotateY(108deg) translateZ(500px);
}
#photo_box img:nth-child(5){
transform: rotateY(144deg) translateZ(500px);
}
#photo_box img:nth-child(6){
transform: rotateY(180deg) translateZ(500px);
}
#photo_box img:nth-child(7){
transform: rotateY(216deg) translateZ(500px);
}
#photo_box img:nth-child(8){
transform: rotateY(252deg) translateZ(500px);
}
#photo_box img:nth-child(9){
transform: rotateY(288deg) translateZ(500px);
}
#photo_box img:nth-child(10){
transform: rotateY(324deg) translateZ(500px);
}
#photo_box img:nth-child(11){
transform: rotateY(360deg) translateZ(500px);
}
/*采用@keyframes 规则创建run动画。*/
@keyframes run {
0%{transform: rotateX(0deg) rotateY(0deg);
}
25%{transform: rotateX(10deg) rotateY(90deg);
}
50%{transform: rotateX(0deg) rotateY(180deg);
}
75%{transform: rotateX(-10deg) rotateY(270deg);
}
100%{transform: rotateX(0deg) rotateY(360deg);
}
}
#text1 {
float: left;
color:#fff;
width: 150px;
padding:12px 0;
height: 50px;
}
#text2 {
float: right;
width: 100px;
color:#fff;
padding:12px 0;
height: 50px;
}
#text3 {
float: right;
width: 100px;
color:#fff;
padding:12px 0;
height: 50px;
}
</style>
</head>
<body>
<div id="div1">
<div id="text1">欢迎登录!</div>
<div id="text2" onclick="outclick()" >退出</div>
<div id="text3">个人信息</div>
</div>
<div id="div2">
<div id="photo_box">
<img src="image.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
<img src="image4.jpg">
<img src="image5.jpg">
<img src="image6.jpg">
<img src="image7.jpg">
<img src="image8.jpg">
<img src="image9.jpg">
<img src="image10.jpg">
<img src="image11.jpg">
</div>
</div>
</body>
<script>
var name=localStorage.getItem("username");
var div1=document.getElementById("text1");
function outclick() {
localStorage.clear();
window.location.href="登录.html";
}
</script>
</html>