jquery - jquery ui.autocomplete 的兼容性问题

标签 jquery compatibility jquery-ui-autocomplete

我正在使用 jquery ui.autocomplete。这在 IE 11 中运行良好。但是,当我在 Mozilla(最新)或 chrome(最新)中运行我的项目时,我遇到了兼容性问题。我对此有两个问题。

  1. 如何解决此兼容性问题
  2. 处理这些兼容性问题的最佳方法是什么?不同的浏览器有不同的兼容性问题,因此即使我使我的项目与特定浏览器兼容,它仍然可能在另一个浏览器中不兼容。

    有没有办法让项目兼容所有浏览器?

现在,我用来尝试实现此自动完成功能的代码如下:

$(function () {
$.extend($.ui.autocomplete.prototype, {
    _renderMenu: function (ul, items) {
        $(ul).unbind("scroll");
        var self = this;
        self._scrollMenu(ul, items);
    },
    _scrollMenu: function (ul, items) {
        var self = this;
        var maxShow = 10;
        var results = [];
        var pages = Math.ceil(items.length / maxShow);
        results = items.slice(0, maxShow);

        if (pages > 1) {
            $(ul).scroll(function () {
                if (isScrollbarBottom($(ul))) {
                    ++window.pageIndex;
                    if (window.pageIndex >= pages) return;
                    results = items.slice(window.pageIndex * maxShow, window.pageIndex * maxShow + maxShow);
                    //append item to ul
                    $.each(results, function (index, item) {
                        self._renderItem(ul, item);
                    });
                    self.menu.refresh();
                    // size and position menu
                    ul.show();
                    self._resizeMenu();
                    ul.position($.extend({
                        of: self.element
                    }, self.options.position));
                    if (self.options.autoFocus) {
                        self.menu.next(new $.Event("mouseover"));
                    }
                }
            });
        }

        $.each(results, function (index, item) {
            self._renderItem(ul, item);
        });
    }
});
function isScrollbarBottom(container) {
    var height = container.outerHeight();
    var scrollHeight = container[0].scrollHeight;
    var scrollTop = container.scrollTop();
    if (scrollTop >= scrollHeight - height) {
        return true;
    }
    return false;
};
$("#txtfrom").autocomplete({
    source: availableTags,
    minLength: 0,
    delay: 0
}).focus(function () {
    //reset result list's pageindex when focus on
    window.pageIndex = 0;
    $(this).autocomplete("search");
});
$("#txtTo").autocomplete({
    source: availableTags,
    minLength: 0,
    delay: 0
}).focus(function () {
    //reset result list's pageindex when focus on
    window.pageIndex = 0;
    $(this).autocomplete("search");
});});

下面列出了兼容性问题:

  • IE11 - 工作正常。
  • Google Chrome - 滚动条不可见。
  • FireFox - 无法从列表中选择项目。

有人可以告诉我可以采取什么措施来处理此兼容性问题吗?提前致谢。

最佳答案

您是否尝试过更改自动完成下拉菜单的级别?

.ui-autocomplete {
    z-index: 1000;
}

.ui-autocomplete {
    z-index: 10000;;
}

.ui-autocomplete {
    z-index: 10000 !important;
}

关于jquery - jquery ui.autocomplete 的兼容性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25926617/

相关文章:

jQuery UI 自动完成小部件 : modifying response data in "response" event doesn't have any effect

使用键盘时 jQuery 自动完成应该跳过禁用的元素

php - 使用 jquery 通配一个 href id?

jQuery - 使用服务器生成的 id 查找 html 元素

c++ - 使用 Boost 创建具有向后兼容 ABI 的库

iphone - iOS 4和5的兼容性:提示用户更新iOS

javascript - jQuery UI 自动完成 - 在 focusOut 上未选择匹配的选项

javascript - e.preventDefault() 不适用于表单提交

jquery - Html 表单没有在 GET 上向 URL 添加参数

android - API 级别 < 11 的 getCheckedItemCount() 等价物是什么?