问题与IE7 jquery.ui.autocomplete.js [英] Problem with jquery.ui.autocomplete.js on IE7

查看:104
本文介绍了问题与IE7 jquery.ui.autocomplete.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是code。 IE7喷出一个'active.0'为空或不是对象上线39错误,这是:

  input.trigger(activate.autocomplete,[$。数据(活动[0],originalObject)]); $(机构)的触发器(off.autocomplete);

在Firefox /铬/歌剧完美的作品。有任何想法吗?非常感谢和很多AP preciated。

  / * jQuery的自动完成
 * 1.0版
 *由耶胡达·卡茨书面(wycats@gmail.com)和赖因Henrichs(reinh@reinh.com)
 * @Requires jQuery的1.2,jQuery的插件尺寸
 *
 *版权所有2007耶胡达·卡茨,赖因Henrichs
 *双麻省理工学院和GPL下授权:
 * hxxp://www.opensource.org/licenses/mit-license.php
     * hxxp://www.gnu.org/licenses/gpl.html
 *
 * // *
 *使用preloaded或阿贾克斯JSON数据源@description表单自动完成插件
 *
 * @example $('#输入用户名')自动完成({名单:昆汀,亚当,管理员]})。
 * @desc简单的自动完成基本的JSON数据源
 *
 * @example $('#输入用户名')自动完成({阿贾克斯:/usernames.js})。
 * @desc使用Ajax简单自动完成加载JSON数据源
 *
 * /
(函数($){  $的.ui = $的.ui || {}; $ .ui.autocomplete = $ .ui.autocomplete || {}; VAR活跃;  $ .fn.autocompleteMode =功能(集装箱,输入,大小,选择){
    VAR原= input.val();变种选定= -1; VAR自我=这一点;    $。数据(document.body的autocompleteMode,真正的);    $(身体)。一(cancel.autocomplete功能(){
      input.trigger(cancel.autocomplete); $(机构)的触发器(off.autocomplete); input.val(原件);
    });    $(身体)。一(activate.autocomplete功能(){
      input.trigger(activate.autocomplete,[$的.data(活性[0],originalObject)]); $(机构)的触发器(off.autocomplete);
    });    $(身体)。一(off.autocomplete功能(即重置){
      container.remove();
      $。数据(document.body的autocompleteMode,FALSE);
      input.unbind(keydown.autocomplete);
      $(\"body\").add(window).unbind(\"click.autocomplete\").unbind(\"cancel.autocomplete\").unbind(\"activate.autocomplete\");
    });    //如果点击气泡一路攀升到窗口,关闭自动完成
    ({$(机构)的触发器(cancel.autocomplete);}click.autocomplete功能())$(窗口).bind;    VAR选择=功能(){
      激活= $(> *,容器).removeClass(活动),片(选择,选择+ 1).addClass(活动)。
      input.trigger(itemSelected.autocomplete,[$的.data(活性[0],originalObject)]);
      input.val(opt.insertText($数据(活性[0],originalObject)));
    };    container.mouseover(函数(五){
      //如果你将鼠标悬停在容器内,而不是它的孩子,回报
      如果(e.target ==容器[0])的回报;
      //设置所选项目到项目上空盘旋,并使其活跃
      选择= $(> *,容器)的.index($(e.target)。是(礼)$(e.target)[0]:$(e.target)。家长(礼? ')[0]);选择();
    })绑定(click.autocomplete功能(E){
      $(机构)的触发器(activate.autocomplete); $。数据(document.body的SUP pressKey,FALSE);
    });    输入
      .bind(keydown.autocomplete功能(E){
        如果(e.which == 27){$(机构)的触发器(cancel.autocomplete); }
        否则,如果(e.which == 13){$(机构)的触发器(activate.autocomplete); }
        否则,如果(e.which == || 40 == e.which 9 || e.which == 38){
          开关(e.which){
            案例40:
            案例9:
              选择=选择> =大小 - 1? 0:选择+ 1;打破;
            案例38:
              选定=选中&下; = 0?大小 - 1:选择 - 1;打破;
            默认:打破;
          }
          选择();
        }其他{返回true; }
        $。数据(document.body的SUP pressKey,真正的);
      });
  };  $ .fn.autocomplete =功能(选择){    选择= $ .extend({},{
      超时:1000,
      的GetList:功能(输入){input.trigger(updateList,[opt.list]); },
      模板:功能(STR){返回<立GT; + opt.insertText(STR)+< /李>中; },
      insertText:功能(STR){返回海峡; },
      匹配:功能(输入){返回this.match(新的RegExp(类型)); },
      包装:< UL类='JQ-UI的自动完成'>< / UL>中
    },选择);    如果($。ui.autocomplete.ext){
      为(在$ .ui.autocomplete.ext VAR EXT){
        如果(选择[​​转]){
          选择= $ .extend(选择,$ .ui.autocomplete.ext [转](OPT));
          删除选择[转]
        }
    }}    返回this.each(函数(){      $(本)
        .KEY preSS(函数(五){
          VAR typingTimeout = $。数据(这一点,typingTimeout);
          如果(typingTimeout)window.clearInterval(typingTimeout);          如果($。数据(document.body的SUP pressKey))
            返回$。数据(document.body的SUP pressKey,FALSE);
          否则,如果($数据(document.body的autocompleteMode)及&安培; e.char $ C $℃下32安培;&安培;!e.key code = 8安培;&安培; e.key !code = 46)返回false;
          其他{
            $。数据(这一点,typingTimeout,window.setTimeout(函数(){
              $(e.target).trigger(自动完成);
            },opt.timeout));
          }
        })
        .bind(自动完成功能(){
          VAR自我= $(本);          self.one(updateList功能(即表){
            名单= $(名单)
              .filter(函数(){返回opt.match.call(this.toLowerCase(),self.val());})
              .MAP(函数(){
                变种节点= $(opt.template(本))[0];
                $。数据(节点,originalObject,这一点);
                返回节点;
              });            $(机构)的触发器(off.autocomplete);            如果(List.length的数字!)返回false;            。VAR容器= list.wrapAll(opt.wrapper)。家长(:最后一个)儿童();            变种偏移= self.offset();            opt.container =容器
              的.css({顶:offset.top + self.outerHeight(),左:offset.left,宽度:self.width()})
              .appendTo(身体);            $(机构)autocompleteMode(集装箱,自我,List.length的数字,选择)。
          });          opt.getList(个体经营);
        });    });
  };})(jQuery的);


解决方案

查看:

<一个href=\"http://github.com/istruble/jquery-autocomplete/commit/bdc926bd2c18c3ebab4e31463a8ae899fd761316#diff-1\" rel=\"nofollow\">http://github.com/istruble/jquery-autocomplete/commit/bdc926bd2c18c3ebab4e31463a8ae899fd761316#diff-1

这与大多数固定的IE 7的问题的一个版本jquery.ui.autocomplete.js的。我发现我在底部列出了一些更多的问题以及如何解决这些问题。

Here is the code. IE7 spouts an "'active.0' is null or not an object" error on line 39, which is:

input.trigger("activate.autocomplete", [$.data(active[0], "originalObject")]); $("body").trigger("off.autocomplete");

Works perfectly in Firefox/Chrome/Opera. Any ideas? Many thanks and much appreciated.

/* jQuery Autocomplete
 * Version 1.0
 * Written by Yehuda Katz (wycats@gmail.com) and Rein Henrichs (reinh@reinh.com)
 * @requires jQuery v1.2, jQuery dimensions plugin
 *
 * Copyright 2007 Yehuda Katz, Rein Henrichs
 * Dual licensed under the MIT and GPL licenses:
 *   hxxp://www.opensource.org/licenses/mit-license.php
     *   hxxp://www.gnu.org/licenses/gpl.html
 *
 */

/*
 * @description Form autocomplete plugin using preloaded or Ajax JSON data source 
 *
 * @example $('input#user-name').autocomplete({list: ["quentin", "adam", "admin"]})
 * @desc Simple autocomplete with basic JSON data source
 *
 * @example $('input#user-name').autocomplete({ajax: "/usernames.js"})
 * @desc Simple autocomplete with Ajax loaded JSON data source
 *
 */


(function($) {

  $.ui = $.ui || {}; $.ui.autocomplete = $.ui.autocomplete || {}; var active;

  $.fn.autocompleteMode = function(container, input, size, opt) { 
    var original = input.val(); var selected = -1; var self = this;

    $.data(document.body, "autocompleteMode", true);

    $("body").one("cancel.autocomplete", function() { 
      input.trigger("cancel.autocomplete"); $("body").trigger("off.autocomplete"); input.val(original); 
    });

    $("body").one("activate.autocomplete", function() {
      input.trigger("activate.autocomplete", [$.data(active[0], "originalObject")]); $("body").trigger("off.autocomplete");
    });

    $("body").one("off.autocomplete", function(e, reset) {
      container.remove();
      $.data(document.body, "autocompleteMode", false);
      input.unbind("keydown.autocomplete");
      $("body").add(window).unbind("click.autocomplete").unbind("cancel.autocomplete").unbind("activate.autocomplete");
    });

    // If a click bubbles all the way up to the window, close the autocomplete
    $(window).bind("click.autocomplete", function() { $("body").trigger("cancel.autocomplete"); });

    var select = function() {
      active = $("> *", container).removeClass("active").slice(selected, selected + 1).addClass("active");
      input.trigger("itemSelected.autocomplete", [$.data(active[0], "originalObject")]);     
      input.val(opt.insertText($.data(active[0], "originalObject")));
    };

    container.mouseover(function(e) {
      // If you hover over the container, but not its children, return
      if(e.target == container[0]) return;
      // Set the selected item to the item hovered over and make it active
      selected = $("> *", container).index($(e.target).is('li') ? $(e.target)[0] : $(e.target).parents('li')[0]); select();
    }).bind("click.autocomplete", function(e) {
      $("body").trigger("activate.autocomplete"); $.data(document.body, "suppressKey", false); 
    });

    input
      .bind("keydown.autocomplete", function(e) {
        if(e.which == 27) { $("body").trigger("cancel.autocomplete"); }
        else if(e.which == 13) { $("body").trigger("activate.autocomplete"); }
        else if(e.which == 40 || e.which == 9 || e.which == 38) {
          switch(e.which) {
            case 40: 
            case 9:
              selected = selected >= size - 1 ? 0 : selected + 1; break;
            case 38:
              selected = selected <= 0 ? size - 1 : selected - 1; break;
            default: break;
          }
          select();
        } else { return true; }
        $.data(document.body, "suppressKey", true);
      });
  };

  $.fn.autocomplete = function(opt) {

    opt = $.extend({}, {
      timeout: 1000,
      getList: function(input) { input.trigger("updateList", [opt.list]); },
      template: function(str) { return "<li>" + opt.insertText(str) + "</li>"; },
      insertText: function(str) { return str; },
      match: function(typed) { return this.match(new RegExp(typed)); },
      wrapper: "<ul class='jq-ui-autocomplete'></ul>"
    }, opt);

    if($.ui.autocomplete.ext) {
      for(var ext in $.ui.autocomplete.ext) {
        if(opt[ext]) {
          opt = $.extend(opt, $.ui.autocomplete.ext[ext](opt));
          delete opt[ext];
        }
    } }

    return this.each(function() {

      $(this)
        .keypress(function(e) {
          var typingTimeout = $.data(this, "typingTimeout");
          if(typingTimeout) window.clearInterval(typingTimeout);

          if($.data(document.body, "suppressKey"))
            return $.data(document.body, "suppressKey", false);
          else if($.data(document.body, "autocompleteMode") && e.charCode < 32 && e.keyCode != 8 && e.keyCode != 46) return false;          
          else {
            $.data(this, "typingTimeout", window.setTimeout(function() { 
              $(e.target).trigger("autocomplete"); 
            }, opt.timeout));
          }
        })
        .bind("autocomplete", function() {
          var self = $(this);

          self.one("updateList", function(e, list) {
            list = $(list)
              .filter(function() { return opt.match.call(this.toLowerCase(), self.val()); })
              .map(function() {
                var node = $(opt.template(this))[0];
                $.data(node, "originalObject", this);
                return node; 
              });

            $("body").trigger("off.autocomplete");

            if(!list.length) return false;

            var container = list.wrapAll(opt.wrapper).parents(":last").children();

            var offset = self.offset();

            opt.container = container
              .css({top: offset.top + self.outerHeight(), left: offset.left, width: self.width()})
              .appendTo("body");

            $("body").autocompleteMode(container, self, list.length, opt);
          });

          opt.getList(self);
        });

    });
  };

})(jQuery);

解决方案

Check out:

http://github.com/istruble/jquery-autocomplete/commit/bdc926bd2c18c3ebab4e31463a8ae899fd761316#diff-1

It is a version of jquery.ui.autocomplete.js with most of the IE 7 issues fixed. I found a few more issues which I listed at the bottom along with how to fix them.

这篇关于问题与IE7 jquery.ui.autocomplete.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆