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

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

问题描述

我使用jQuery UI自动完成组合框控件。当我在我的组合框添加占位符,自动完成框默认情况下打开。

这发生的仅在IE10后来

这是我的code:

  _create:功能(){
            this.wrapper = $(&所述;跨度>中)
            .addClass(自定义组合框)
            .insertAfter(this.element);
            this.element.hide();
            this._createAutocomplete();
            this._createShowAllButton();
            this.input.attr(占位符,this.element.attr('占位'));
        },


解决方案

我们注意到,这个问题正在被解决实际聚焦的组合框的。

一旦组合框聚焦,自动完成框消失,它仍然在组合框的失去的焦点。

这方法

所以,我们的解决方案是有点的破解杂交的,我们增加了一个。重点()后跟一个 .blur()

  _create:功能(){
            this.wrapper = $(&所述;跨度>中)
            .addClass(自定义组合框)
            .insertAfter(this.element);
            this.element.hide();
            this._createAutocomplete();
            this._createShowAllButton();
            this.input.attr(占位符,this.element.attr('占位'));            this.input.focus()模糊()。
          // ^^^^^^^^^^^^^^^^^^^^^^^^^^瞧!
        },

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

解决方案

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

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

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