JQUery自动完成程序在IE8中无法正常工作

时间:2010-04-14 17:55:56

标签: jquery jquery-autocomplete

我有一些在firefox和chrome中运行的脚本,但在IE 8中我收到此错误:

$.Autocompleter.defaults = {
    inputClass: "ac_input",
    resultsClass: "ac_results",
    loadingClass: "ac_loading",
    minChars: 1,
    delay: 400,
    matchCase: false,
    matchSubset: true,
    matchContains: false,
    cacheLength: 10,
    max: 100,
    mustMatch: false,
    extraParams: {},
    selectFirst: true,
//the following line throws the error, read down for error message
    formatItem: function(row) { return row[0]; },
    formatMatch: null,
    autoFill: false,
    width: 0,
    multiple: false,
    multipleSeparator: ", ",
    highlight: function(value, term) {
        return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>])(" + term.replace(/([\^\$()[]{}*.+\?\|\])/gi, "\$1") + ")(?![^<>]>)(?![^&;]+;)", "gi"), "$1");
    },
    scroll: true,
    scrollHeight: 180
};
` 特定错误读取:'0'为空或不是对象

我可以将行[0]更改为某些内容吗?这可以在jquery.autocomplete.js中找到,它在firefox中读取相同并且不会导致错误,因此我真的不想在可能的情况下更改此内容。

任何建议都会有所帮助!

1 个答案:

答案 0 :(得分:1)

这就是我正在做的事情(基本上我使用了formatItem函数但是把它拿出来并尝试了你所做的并且它有效。

function setSearchAutoComplete() {
    $("#txtContactSearch").autocomplete
   ("../DataFiles/MaintainMessages.ashx?what=GU",
       {
           //formatItem: formatItem,
           formatItem:function(row){return "<em>" + row[0] + "<em>";},
           selectFirst: true,
           minChars: 2,
           max: 50,
           cache: false
       }
   );
    $("#txtContactSearch").result(findValueCallback);
}

function findValueCallback(event, data, formatted) {
    $("#divSelectedContacts").append("<span id='C" + data[1] + "' class='selectedContact'>" + data[0] + "</span>");
}

function formatItem(row) {
    return "<em>" + row[0] + "<em>";
}

HTH

相关问题