<body>
    <input type="text">
    <input type="search" class="search">
    <script>
        // 获得焦点 onfocus
        document.querySelector("input").
                onfocus = function(){
                    this.value = "长青吴彦祖";
                };
        // 失去焦点 onblur
                document.querySelector("input").onblur = function(){
                    this.value = "wwww";
                }
        // 输入oninput
        document.querySelector("input").oninput = function(){
            console.log(this.value);
             // 这个和百度搜索差不多
        }
 
        // 改变 onchange
        document.querySelector("input").onchange = function(){
            console.log(this.value);
            // 这个是利用敲回车(就是脱离焦点)之后才出现
        }
 
 
 
        // 文本被选择上 onselect
        document.querySelector("input").onselect = function(){
            alert("不允许剪切文本");
        }
        // onsearch 搜索
        document.querySelector(".search").onsearch = function(){
            console.log(this.value);
           // 这个后面会出现"x"   删除之前所打出的文字
        }
 
    </script>

相关文章:

  • 2022-12-23
  • 2021-11-18
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-09-06
猜你喜欢
  • 2021-12-09
  • 2021-11-18
  • 2021-12-07
  • 2022-12-23
  • 2021-12-22
  • 2021-04-11
  • 2022-12-23
相关资源
相似解决方案