js防抖
<html>
   <body>
   <h2>js防抖</h2>
   <input placeholder="请输入电话"/>
    <script>
        let telInput=document.querySelector("input")
        telInput.addEventListener('input',noDou(demo,1000))
        //防抖封装
        function noDou(fn,wait){
            let timeOut=null;
            return args=>{
                if(timeOut) clearTimeout(timeOut)
                timeOut=setTimeout(fn,wait)
            }
        }
        function demo(){
            console.log("发起请求")
        }
    </script>
   </body>
</html>


复制内容


评论


乖,登录后才可以留言! 登录

Copyright © 2020-2023 春藤技术,春藤建站 All Rights Reserved
备案号:豫ICP备20020705号 公网安备 51LA统计
0.230138s