精准定位
2016-02-25 10:55 孤独大兔子 阅读(337) 评论(0) 编辑 收藏 举报//精准去词定位 function LookMatch() { } LookMatch.init = function(seach, els) { var that = new LookMatch(); that._setElement(seach, els); } LookMatch.initmany = function(warp) { var that ,seach,els; warp.each(function(index,item){ that = new LookMatch(); seach = $(item).find('input'); els = $(item).find('ul'); that._setElement(seach, els); }) } LookMatch.prototype._setElement = function(seach, ul) { this.seachEl = seach; this.ul = ul; this.backEls = this.ul.clone(true); var that = this; this.ul.on('click', 'li', function() { that.seachEl.val($(this).text()); that.ul.hide(); that.restore(); }); this.seachEl.on('focus', function() { that.ul.show(); }).on('blur',function(){ console.log('ss'); setTimeout(function(){ that.ul.hide(); },100) }) this.seachEl.next().on('click', function() { that.ul.show(); }); this.seachEl.on('keyup', function() { var q = $(this).val(); if (!q) { that.restore(); return; } var arr = []; that.ul.find('li').each(function(i, e) { var text = $(this).text(); var indexof = text.indexOf(q); if (indexof != -1) { arr.push(e); } }); if (!arr.length) { return; } $.each(arr.reverse(), function(i, e) { that.ul.prepend(e); }); }) } LookMatch.prototype.restore = function() { this.ul.empty().html(this.backEls.html()); } // 搜索框,列表 LookMatch.initmany($('.wordposition'));
*
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步