京东或者淘宝获取焦点事件

1.<label for=” 跳转到想要的Id“>
2.文本框获取焦点onfocus(焦点就是插入条光标)
3.失去焦点事件onblur
4.输入事件oninput(文字的输入和删除都会触发事件)
在这里插入图片描述

在这里插入代码片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        input{
            width:300px;
            height: 36px;
            padding-left: 5px;
            color: #cccccc;
        }
        label{
            position: absolute;
            top:83px;
            left:65px;
            font-size: 13px;
            color: #cccccc;
            cursor: pointer;
        }
        .hide{
            display: none;
        }
    </style>
</head>
<body>
京东:<input id="inp1"  type="text" value="我是京东"><br><br>
淘宝:<label for="inp2">我是淘宝</label><input id="inp2" type="text" ><br><br>
placeholder:<input type="text" placeholder="我是placeholder">
<script>
    //京东获取焦点
    var inp1=document.getElementById("inp1");
    inp1.function () {
        if(this.value==="我是京东")
        {
            inp1.value="";
        }
    }

    inp1.function () {
        if(this.value===""){
            inp1.value="我是京东";
        }
    }

    //淘宝获取焦点
    var inp2=document.getElementById("inp2");
    var lab=document.getElementsByTagName("label")[0];
    inp2.function () {
        if(this.value===""){
            lab.className="";
        }else {
            lab.className="hide";
        }
    }
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/zuo_zuo_blog/article/details/89059714
今日推荐