学习布局(20) 表单

18 篇文章 0 订阅
14 篇文章 0 订阅

 .wrap {
            margin: 0 auto;
            width:400px;
            padding: 20px;
            border: 1px solid red;
        }

        .user, .pass {
            height: 46px;
            border: 1px solid #d9d9d9;
            padding-left: 48px;
            line-height: 46px;
            position: relative;
        }

        .user {
            margin-bottom: 10px;
            background: url("../images/user.png") 0 0 no-repeat;
        }

        .pass {
            background: url("../images/pass.png") 0 0 no-repeat;
        }

        .wrap label, .wrap input {
            position: absolute;
            top: 0px;
            left: 48px;
        }

        .wrap input {
            width: 320px;
            height: 95%;
            line-height: 46px;
            background: transparent;
            border: none;
            outline: none;
        }

        .wrap label {
            width: 320px;
            height: 95%;
            line-height: 46px;
            z-index: 1;
            background: transparent;
        }
<form class="wrap" action="">
        <div class="user">
            <label id="userLabel" for="username">请输入用户名</label>
            <input  type="text" name="username" id="username"/>
        </div>
        <div class="pass">
            <label id="passLabel" for="password">请输入密码</label>
            <input  type="password" name="password" id="password"/>
        </div>
    </form>

    <script>
        var userText = document.getElementById("username");
        var userLabel = document.getElementById("userLabel");
        var passText = document.getElementById("password");
        var passLabel = document.getElementById("passLabel");

        userText.onkeyup = function () {
            changeLabel(this, userLabel);
        };

        passText.onkeyup = function () {
            changeLabel(this, passLabel);
        }
        
        function changeLabel(ele, labelEle) {
            var val = ele.value.split(" ").join("");
            if (val == "") {
                labelEle.style.display = "block";
                ele.value = "";
            } else {
                labelEle.style.display="none";
            }
        }
        
    </script>

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值