我正在使用 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!
},
关于jquery - 占位符在页面加载时打开 jQuery UI 自动完成组合框 (IE10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28126306/