输入框事件处理

Posted zhang-jiao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了输入框事件处理相关的知识,希望对你有一定的参考价值。

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

代码示例:

<body>
        <input type="text" placeholder="请输入任意内容" id="input">
        <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>

 

以上是关于输入框事件处理的主要内容,如果未能解决你的问题,请参考以下文章