占位符在页面加载时打开 jQuery UI 自动完成组合框 (IE10)

Placeholder opens jQuery UI autocomplete combobox on page load (IE10)

我正在使用 jQuery UI 自动完成组合框小部件。当我在我的组合框中添加占位符时,自动完成框默认打开。

这种情况仅在 IE10 及更高版本上出现。

这是我的代码:

 _create: function () {
            this.wrapper = $("<span>")
            .addClass("custom-combobox")
            .insertAfter(this.element);
            this.element.hide();
            this._createAutocomplete();
            this._createShowAllButton(); 
            this.input.attr("placeholder", this.element.attr('placeholder'));
        },

我们注意到,实际上 聚焦 组合框可以解决这个问题。

一旦组合框获得焦点,自动完成框就会消失,当组合框 失去 焦点时,它会保持原样。

因此,我们的解决方案有点 hack-ish,我们添加了一个 .focus() 后跟一个 .blur() :

 _create: function () {
            this.wrapper = $("<span>")
            .addClass("custom-combobox")
            .insertAfter(this.element);
            this.element.hide();
            this._createAutocomplete();
            this._createShowAllButton(); 
            this.input.attr("placeholder", this.element.attr('placeholder'));

            this.input.focus().blur();
          //^^^^^^^^^^^^^^^^^^^^^^^^^^ Voila!
        },

我们在 IE10+ 中遇到了同样的问题,但是当我们添加一个带有 特殊字符的占位符时 (德语 "Umlaute")。

Seckin 的解决方案也解决了我们的问题 - 经过 1 天的艰苦工作 Google ;-)

试图为答案投票 - 但作为新手,我没有这样做的声誉...

_create: function () {
        this.wrapper = $("<span>")
        .addClass("custom-combobox")
        .insertAfter(this.element);
        this.element.hide();
        this._createAutocomplete();
        this._createShowAllButton(); 

        this.input.attr( "placeholder", 'Bitte wählen' );
        this.input.focus().blur();

    },