zoukankan      html  css  js  c++  java
  • 精准定位

    //精准去词定位
      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'));

    *

  • 相关阅读:
    spring 实现测试解耦
    Java 反射实例 (二)
    Java 反射实例
    Thread.join()
    缓存输入/输出流
    文件的拷贝
    将键盘输入的数据保存到文件中:OutputStream
    InputStream中read方法各个参数的意义
    OutputStream
    InputStream中的主要的子类
  • 原文地址:https://www.cnblogs.com/change-oneself/p/5216190.html
Copyright © 2011-2022 走看看