jQuery自动完成 - IE8问题 - 此选项卡已恢复

Ila*_*sda 6 javascript internet-explorer jquery-ui jquery-ui-autocomplete

我遇到了jQuery UI的问题 - 自动完成和IE8.

我正在使用combobox你可以在jQuery UI网站上找到的方法 - 这里
基本上,它是从select/option列表创建自动完成输入+选择菜单.

我正在使用jQuery 1.6.4和jQuery UI 1.8.16; 两者都来自谷歌服务器.

它在Chrome/FF/Opera上完美运行,但在IE8上无效.

在IE8上 - 一旦你选择了某些东西(打字后),或者使用下拉按钮IE将重新加载页面.请注意,在使用箭头或尝试选择某些内容之前,IE不会崩溃.

  • res://ieframe.dll/acr_error.htm#, 在URL中,在实际路径前面
  • 或者是一条消息 this tab has been reloaded; a problem with the page causes IE to close and reopen the page

这里有实例

知道是什么导致IE这样做吗?任何建议都非常感谢.


jQuery代码:

    <script>
    (function( $ ) {
        $.widget( "ui.combobox", {
            _create: function() {
                var self = this,
                    select = this.element.hide(),
                    selected = select.children( ":selected" ),
                    value = selected.val() ? selected.text() : "";
                var input = this.input = $( "<input>" )
                    .insertAfter( select )
                    .val( value )
                    .autocomplete({
                        delay: 0,
                        minLength: 0,
                        source: function( request, response ) {
                            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
                            response( select.children( "option" ).map(function() {
                                var text = $( this ).text();
                                if ( this.value && ( !request.term || matcher.test(text) ) )
                                    return {
                                        label: text.replace(
                                            new RegExp(
                                                "(?![^&;]+;)(?!<[^<>]*)(" +
                                                $.ui.autocomplete.escapeRegex(request.term) +
                                                ")(?![^<>]*>)(?![^&;]+;)", "gi"
                                            ), "<strong>$1</strong>" ),
                                        value: text,
                                        option: this
                                    };
                            }) );
                        },
                        select: function( event, ui ) {
                            ui.item.option.selected = true;
                            self._trigger( "selected", event, {
                                item: ui.item.option
                            });
                        },
                        change: function( event, ui ) {
                            if ( !ui.item ) {
                                var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
                                    valid = false;
                                select.children( "option" ).each(function() {
                                    if ( $( this ).text().match( matcher ) ) {
                                        this.selected = valid = true;
                                        return false;
                                    }
                                });
                                if ( !valid ) {
                                    // remove invalid value, as it didn't match anything
                                    $( this ).val( "" );
                                    select.val( "" );
                                    input.data( "autocomplete" ).term = "";
                                    return false;
                                }
                            }
                        }
                    })
                    .addClass( "ui-widget ui-widget-content ui-corner-left" );

                input.data( "autocomplete" )._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                        .data( "item.autocomplete", item )
                        .append( "<a>" + item.label + "</a>" )
                        .appendTo( ul );
                };

                this.button = $( "<button type='button'>&nbsp;</button>" )
                    .attr( "tabIndex", -1 )
                    .attr( "title", "Show All Items" )
                    .insertAfter( input )
                    .button({
                        text: false
                    })
                    .removeClass( "ui-corner-all" )
                    .click(function() {
                        // close if already visible
                        if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
                            input.autocomplete( "close" );
                            return;
                        }

                        // work around a bug (likely same cause as #5265)
                        $( this ).blur();

                        // pass empty string as value to search for, displaying all results
                        input.autocomplete( "search", "" );
                        input.focus();
                    });
            },

            destroy: function() {
                this.input.remove();
                this.button.remove();
                this.element.show();
                $.Widget.prototype.destroy.call( this );
            }
        });
    })( jQuery );

    $(document).ready( function() {

        $("#combobox").combobox();

    });


    </script>
Run Code Online (Sandbox Code Playgroud)

and*_*dyb 3

我仍在尝试找出IE8 崩溃的原因,但当您向页面添加 jQueryUI 主题时,它确实对我有用,例如:

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/cupertino/jquery-ui.css">
Run Code Online (Sandbox Code Playgroud)

编辑:我想我知道它在哪一行崩溃,但我仍然不知道为什么!在jQueryUI 代码中 activate: function( event, item ) {

以下代码将样式和属性添加到活动项目。

this.active = item.eq(0)
    .children("a")
    .addClass("ui-state-hover")
    .attr("id", "ui-active-menuitem")
    .end();
Run Code Online (Sandbox Code Playgroud)

由于某种原因,IE8 在这里崩溃了,尽管对我来说,有时删除.addClass.attr行时不会崩溃。

编辑 2:好的,由于某种原因 IE 因你的风格而崩溃.ui-autocomplete。如果更改overflow:scroll;overflow:auto;,则 IE8 不会崩溃。或者更改max-height为 just height,这也可以修复它。猜测这是 IE 中的一个错误max-height(可能是IE8 Overflow:auto 和 max-height)或overflow