简易登录界面

html部分:

<!DOCTYPE html>
<html lang="zh-CN">

<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;
        }

        strong {
            font-weight: normal;
        }

        :root {
            background-image: url(./cat-2528119.jpg);
            background-repeat: no-repeat;
        }

        .login {
            width: 800px;
            height: 500px;
            border: 1px solid black;
            border-radius: 50px;
            margin: 100px auto;
            background-color: rgba(255, 255, 255, 0.534);
            box-shadow: 10px 10px 15px rgba(0, 0, 0, 0.7);
            display: flex;
        }

        .img {
            padding-top: 50px;
            width: 300px;
            background-image: url(./cat-2528119.jpg);
            background-position: -1146px -88px;
            background-repeat: no-repeat;
            border-top-left-radius: 50px;
            border-bottom-left-radius: 50px;
        }

        aside {
            width: 500px;
            border-top-right-radius: 50px;
            border-bottom-right-radius: 50px;
            float: right;
            background-color: rgb(255, 255, 255, 1);
            padding: 67px 20px;
            box-sizing: border-box
        }

        ul {
            margin-bottom: 20px;
        }

        ul>li {
            padding-left: 12px;
            box-sizing: border-box;
            height: 50px;
            /* background-color: aquamarine; */
            margin: 10px;
            list-style-type: none;
            line-height: 50px;
            vertical-align: middle;
        }

        ul>li::before {
            display: inline-block;
            vertical-align: middle;
            content: "*";
            font-size: 20px;
            color: red;
        }

        li>span {
            margin-left: 10px;
            width: 86px;
            display: inline-block;
            text-align: left;
            font-size: 17px;
        }

        li>input {
            outline: none;
            width: 188px;
            height: 20px;
            margin: 0 10px;
            padding-left: 8px;
            border-radius: 4px;
            box-sizing: border-box;
            border: none;
            border-bottom: 1px solid black;
            vertical-align: middle;
        }

        aside>button {
            border: 2px solid #2980b9;
            color: #2980b9;
            position: relative;
            overflow: hidden;
            z-index: 1;
            transition: .5s;


            display: block;
            margin: auto;
            width: 150px;
            height: 75px;
            border-radius: 15px;
            cursor: pointer;
            /* border-style: none; */
            background-color: rgb(255, 255, 255);
            color: black;
            font-size: 20px;
        }

        button::before {
            content: "";
            position: absolute;
            z-index: -1;
            width: 0;
            height: 175%;
            left: 0;
            top:-31px;
            background-color: #2980b9;
            transition: ease-in-out .5s;

        }

        button:hover {
            background-color: #2c3e50;
            color: white;
        }

        button:hover::before {
            width: 100%;
            color: white;
        }

        li>strong {
            font-size: 14px;
            display: none;
        }

        .img>h1 {
            font-style: normal;
            text-align: center;
            height: 80px;
            line-height: 100px;
            font-size: 40px;
            font-weight: 900;
            text-shadow: 0 6px 11px black;
            user-select: none;
        }

        aside>p {
            text-align: center;
            color: red;
            font-size: 14px;
            margin-top: 10px;
            display: none;
        }
    </style>
</head>

<body>
    <div class="login">
        <div class="img">
            <h1>Welcome!</h1>
        </div>
        <aside>
            <ul>
                <li>
                    <span>账号:</span>
                    <input type="text" placeholder="使用数字字母下划线,长度6-15">
                    <strong></strong>
                </li>
                <li>
                    <span>密码:</span>
                    <input type="password" placeholder="8-16位,大小写(包括)1位数字">
                    <strong></strong>
                </li>
                <li>
                    <span>确认密码:</span>
                    <input type="password" placeholder="">
                    <strong></strong>
                </li>
                <li>
                    <span>邮箱:</span>
                    <input type="email" placeholder="">
                    <strong></strong>
                </li>
                <li>
                    <span>手机号:</span>
                    <input type="text" placeholder="">
                    <strong></strong>
                </li>
            </ul>
            <button>确认注册</button>
            <p>tips:红色带*号的是必填项</p>
        </aside>
    </div>
    <script src="login.js"></script>
</body>

</html>

JS部分:

js部分利用正则表达式基本原理来完成,此部分只是试作,需要其他内容还请自行添加

let input = document.querySelectorAll('input');
let strong = document.querySelectorAll('li>strong');
let btn = document.querySelector('aside>button');
let p = document.querySelector('aside>p');
Login(0, /^[a-zA-Z_]\w{5,14}$/);
Login(1, /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/);
Login(2, /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/);
Login(3, /^\w+@\w+(\.\w+)+$/);
Login(4, /^1(3|4|5|6|7|8|9)\d{9}$/);
function Login(key, reg) {
    input[key].onblur = function () {
        let invalue = input[key].value;
        strong[key].style.color = '';
        strong[key].style.display = 'inline-block';
        if (invalue == '') {
            strong[key].innerText = '内容不能为空';
            strong[key].style.color = 'red';

        } else if (reg.test(invalue)) {
            strong[key].innerText = '格式正确';
            strong[key].style.color = 'green';
            if (input[1].value === input[2].value) {
                strong[2].innerText = '密码相同';
                strong[2].style.color = 'green';
            } else {
                strong[2].innerText = '检查密码';
                strong[2].style.color = 'red';
            }

        } else {
            strong[key].innerText = '格式错误';
            strong[key].style.color = 'red';

        }
    }
}
for (let i = 0; i < input.length; i++) { 
    btn.onclick = () => { 
        if (input[i].value != '') {
            alert('注册成功,等待页面跳转');
        } else { 
            alert('注册失败,请仔细检查');
            p.style.display = 'block';
        }
    }
}

效果图:

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值