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

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

仅在IE10及更高版本上发生。

这是我的代码:

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

我们注意到问题是通过实际聚焦combobox来解决的。

一旦combobox被聚焦,自动完成框就消失了,当combobox失去焦点时它仍然保持这种状态。

所以,我们的解决方案有点黑客攻击 ,我们添加了一个.focus()后跟一个.blur()

  _create: function () { this.wrapper = $("") .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的解决方案也解决了我们的问题 – 经过一天艰苦的Google工作;-)

试图投票给答案 – 但作为一个新手,我没有这样做的声誉……

 _create: function () { this.wrapper = $("") .addClass("custom-combobox") .insertAfter(this.element); this.element.hide(); this._createAutocomplete(); this._createShowAllButton(); this.input.attr( "placeholder", 'Bitte wählen' ); this.input.focus().blur(); },