问题
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