【问题标题】:Placeholder opens jQuery UI autocomplete combobox on page load (IE10)占位符在页面加载时打开 jQuery UI 自动完成组合框(IE10)
【发布时间】:2015-03-23 11:02:48
【问题描述】:

我正在使用 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'));
        },

【问题讨论】:

  • 请写一些关于这个问题的更多细节。

标签: jquery jquery-ui autocomplete placeholder


【解决方案1】:

我们注意到问题正在通过实际聚焦组合框得到解决。

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

所以,我们的解决方案有点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!
        },

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 我真的很高兴它有帮助!感谢@oekokroete 的信任,但是因为它是相同的解决方案;我认为这不应该是一个答案,欢迎您将其添加为对现有答案的评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 2011-11-16
    • 1970-01-01
    相关资源
    最近更新 更多