<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.main {
width: 300px;
height: 300px;
border: 1px solid #bbb;
}
.login {
float: left;
}
.register {
float: left;
}
.loginInput {}
.registerInput {
display: none;
}
</style>
</head>
<body>
<div class="main">
<div class="login">登录</div>
<div class="register">注册</div><br />
<div class="loginInput"><input type="text" placeholder='邮箱' class="mailboxLogin"><input type="text"
placeholder='密码' class="passwordLogin"><br />
<div class="messageLogin"></div><button class="loginBtn">登录</button>
</div>
<div class="registerInput"><input type="text" placeholder='用户名' class="userNameRegister"><input type="text"
placeholder='邮箱' class="mailboxRegister"><input type="text" placeholder='密码'
class="passwordRegister"><br />
<div class="messageRegister"></div><button class="registerBtn">注册</button>
</div>
</div>
<script src="./jquery.min.js"></script>
<script>
$('.login').click(function () {
$(".registerInput").css("display", "none");
$(".loginInput").css("display", "block");
})
$('.register').click(function () {
$(".loginInput").css("display", "none");
$(".registerInput").css("display", "block");
})
var reg = new RegExp('^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$', '');
$('.loginBtn').click(function () {
String.prototype.NoSpace = function () {
return this.replace(/\s+/g, "");
};
var messageLogin = ''
if (reg.test($('.mailboxLogin').val().NoSpace()) === false) {
messageLogin = '邮箱格式错误'
} else if ($('.passwordLogin').val().NoSpace() == '') {
messageLogin = '密码为空'
} else {
$.ajax({
type: 'POST',
url: 'http://8.140.34.53:3000/api/signin',
data: { 'email': $('.mailboxRegister').val(), 'password': $('.passwordRegister').val() },
success: function (data) {
console.log(data);
}
})
}
$('.messageLogin').text(messageLogin)
})
$('.registerBtn').click(function () {
String.prototype.NoSpace = function () {
return this.replace(/\s+/g, "");
};
var messageRegister = ''
if ($('.userNameRegister').val().NoSpace() == '') {
messageRegister = '用户名为空'
} else if (reg.test($('.mailboxRegister').val().NoSpace()) === false) {
messageRegister = '邮箱格式错误'
} else if ($('.passwordRegister').val().NoSpace().length < 6) {
messageRegister = '密码要大于六位数'
} else {
$.ajax({
type: 'POST',
url: 'http://8.140.34.53:3000/api/signup',
data: { 'name': $('.userNameRegister').val(), 'email': $('.mailboxRegister').val(), 'password': $('.passwordRegister').val() },
success: function (data) {
console.log(data);
}
})
}
$('.messageRegister').text(messageRegister)
})
</script>
</body>
</html>