输入框模糊搜索
<input id="box-xs" type="text"/>
//防抖
function debounce(fn, delay) {
let delays = delay || 1000;
let timer;
return function () {
let th = this;
let args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function () {
timer = null;
fn.apply(th, args);
}, delays);
};
}
$("#box-xs").on("input propertychange", debounce(searchInput))
function searchInput(){
//这个函数是实现模糊搜索的主要函数,所有的逻辑和数据请求以及渲染在这个里面实现
}
做项目时遇到很多需要模糊搜索功能的模块,但是自己也记不住代码,以此记录,也希望可以帮助到有需要的人!