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

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>

2.文本框获取焦点事件

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        input{
            display: block;
            margin: 5px ;
        }
    </style>
</head>
<body>
    <ul>
        <input type="text">
        <input type="text">
        <input type="text">
        <input type="text">
        <input type="text">
        <input type="text">
        <button>设置</button>
    </ul>
    <script>
        //点击设置按钮,让所有的input标签获取焦点后高亮显示
      /*  var btn=document.getElementsByTagName("button");*/
        var inpArr=document.getElementsByTagName("input");
        var button=inpArr[inpArr.length-1].nextElementSibling||inpArr[inpArr.length-1].nextSibling;
        button.function () {
            for(var i=0;i<inpArr.length;i++){
                inpArr[i].function () {
                    this.style.border="2px solid #ccc";
                    this.style.backgroundColor="pink"
                }
                inpArr[i].function () {
                    this.style.border="";
                    this.style.backgroundColor=""
                }
            }
        }
    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值