精准定位
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了精准定位相关的知识,希望对你有一定的参考价值。
function LookMatch(){ } LookMatch.init = function(seach,els){ var that = new LookMatch(); 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(){ console.log(‘ss‘); 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.init($(‘#seachinput‘),$(‘#uu‘));
*
以上是关于精准定位的主要内容,如果未能解决你的问题,请参考以下文章