js 实现动态搜索请求

时间:2021-09-02 11:13:47

目的是搜索框保证最后一次键入会成功发送请求,同时也能有一定动态搜索;


$('#searchInput').on("keyup",function(e){

            $("#mess").hide();

            $("#tn_emailBox").hide();

            clearTimeout(seach_timer);

            seach_timer = setTimeout(function(){

                var str = $('#searchInput').val();

                if(str!==''){

                    self.search(str);

                }

            },500)

        });