自动完成功能适用于Chrome,但不适用于IE

AutoComplete Works in Chrome but not IE

本文关键字:适用于 不适用 IE Chrome 成功 功能      更新时间:2023-10-05

我正在尝试设置一个具有自动完成功能的搜索框。这是我的一个朋友写的,但他也无法在IE中使用。它的镀铬效果很好。它需要在IE中工作,因为使用它的人没有Chrome。这是代码:

<style>
    .ui-autocomplete-category {
        font-weight: bold;
        padding: .4em .8em;
        margin: 1.0em 0 .4em;
        line-height: 1.5;
    }
</style>
<script>
    $j.widget("custom.Complete", $j.ui.autocomplete, {
        _renderMenu: function (ul, items) {
            var that = this,
                currentCategory = "";
            $j.each(items, function (index, item) {
                if (item.category != currentCategory) {
                    ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
                    currentCategory = item.category;
                }
                that._renderItemData(ul, item);
            });
        }
    });
</script>
<script>
    $j(function () {
        var data = [{
            label: "Call types",
            category: "Call Flow"
        }, {
            label: "Review",
            category: "Call Flow"
        }, {
            label: "Mikatron",
            category: "Decepticon"
        }, {
            label: "Eric Prime",
            category: "Transformer"
        }, ];
        $j("#SearchResult").Complete({
            delay: 0,
            source: data,
            appendTo: '#menu-container',
        });
    });
</script>

有什么想法吗?我已经为此工作了好几个小时了。

IE在对象文字中的尾随逗号上失败(这是非常正确的)。

就在Eric Prime对象之后,您有一个逗号。把它取下来。。。

{
    label: "Eric Prime",
    category: "Transformer"
}, ];

变成这个

{
    label: "Eric Prime",
    category: "Transformer"
}];

更新

这里还有另一个尾随逗号。。。

$j("#SearchResult").Complete({
    delay: 0,
    source: data,
    appendTo: '#menu-container', // <-- here
});