使用jquery UI自动完成键入问题

时间:2011-04-21 09:19:00

标签: jquery jquery-ui

我有问题jquery ui自动完成...当我开始输入单词并且自动完成显示结果时它才开始在我完成单词之前删除字母...任何人都有这个问题?

$(function() {
var rn = Math.floor(Math.random() * 11);
$("#query").autocomplete({
    source: "search.asp?rn=" + rn,
    minLength: 2,
    selectFirst: true,
    delay: 500,
    //autoFocus: true,
    select: function(event, ui) {
        var vp = ui.item.vp;
        var ran = Math.floor(Math.random() * 11);
        if (vp != "-1" && vp != "x") {
            location.href = "menu.asp?rn=" + ran + "&LOC=1&IDP=" + vp;
        }
        else if (vp == 'x') {
            location.href = "result.asp?rn=" + ran + "&term=" + ui.item.value;
        }
    }
});

$.ui.autocomplete.prototype._renderItem = function(ul, item) {
    var sterm = this.term.split(" ");
    $.each(sterm, function(index, value) {
        item.label = item.label.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(value) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<span style='color: #2779AA;'><strong>$1</strong></span>");
    });
    return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.label + "</a>").appendTo(ul);
};

});

1 个答案:

答案 0 :(得分:2)

您使用的是autoFocus插件吗?我遇到了同样的问题并使用以下描述的解决方案修复了它:

https://github.com/scottgonzalez/jquery-ui-extensions/issues/1