form表单事件

<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>
原文地址:https://www.cnblogs.com/cntt/p/6532930.html