占位符在页面加载时打开 jQuery UI 自动完成组合框 (IE10) [英] Placeholder opens jQuery UI autocomplete combobox on page load (IE10)

查看:13
本文介绍了占位符在页面加载时打开 jQuery UI 自动完成组合框 (IE10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery UI 自动完成组合框小部件.当我在组合框上添加占位符时,默认情况下会打开自动完成框.

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

这种情况仅在 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'));
        },

推荐答案

我们注意到通过实际聚焦组合框来解决问题.

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.

所以,我们的解决方案有点hack-ish,我们添加了一个 .focus() 后跟一个 .blur() :

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!
        },

这篇关于占位符在页面加载时打开 jQuery UI 自动完成组合框 (IE10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆