• 输入框获取焦点事件:onfocus
  • 输入框失去焦点事件:onblur

代码示例:

<body>
        <input type="text" placeholder="请输入任意内容" >
        <script>
          //获取DOM元素
           var input=document.getElementById("input");
           //获取焦点
           input.onfocus=function(){
             this.style.width="400px";
             this.style.height="50px";
             this.style.border='2px solid yellow';

           }
           //失去焦点
           input.onblur=function(){
            this.style.color="blue";
            this.style.width="200px";
           }
        </script>
</body>

 

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2021-12-05
  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2021-07-13
  • 2022-01-23
  • 2021-12-17
  • 2022-02-17
相关资源
相似解决方案