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

杀马特。学长 韩版系。学妹 提交于 2019-12-01 03:30:37

问题


I'm using jQuery UI autocomplete combobox widget. When i add placeholders on my comboboxes, the autocomplete boxes are opened by default.

This occurs only on IE10 and later.

This is my code :

 _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'));
        },

回答1:


We noticed that the issue was being solved by actually focusing the comboboxes.

Once the combobox is focused, the autocomplete box disappeared and it remained that way when the combobox lost focus.

So, our solution was a bit hack-ish, we added a .focus() followed by a .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!
        },



回答2:


We had the same problem in IE10+ but just when we add a placeholder with special characters (German "Umlaute").

The solution by Seckin solved also our problem - after 1 day of hard Google work ;-)

Tried to vote for the answer- but as a newbie I haven't the reputation for doing so...

_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();

    },


来源:https://stackoverflow.com/questions/28126306/placeholder-opens-jquery-ui-autocomplete-combobox-on-page-load-ie10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!