JQuery的自动完成功能关闭选项时,单击外 [英] JQuery Autocomplete close option when click outside

查看:109
本文介绍了JQuery的自动完成功能关闭选项时,单击外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有在JQuery的自动完成的方式,如果我点击以外的选项框来选择或点击键盘逃跑的时候被打开的选项。它关闭,而不必选择一个选项。

I would like to know if there's a way in JQuery Autocomplete, when is open the options if I click OUTSIDE the options box to select or click ESCAPE in the keyboard. It closes, without having to select one option.

任何人都知道正确的方式做到这一点?使用的东西,以检查是否集中自动完成,如果不关闭它仍然认为,但仅仅是一个一个的想法。

Anyone know the correct way to do it? Still thought using something to check if focus the autocomplete , if not to close it but is just an a IDEA.

感谢

推荐答案

只是关闭的当对话框关闭自动完成:

Just close the autocomplete when the dialog is closed:

$("#dialog").dialog({
    close: function() {
        $('#tags').autocomplete('close');
    }
});

在行动中看到这个: http://jsfiddle.net/william/3Yz9f/1/

更新

这取决于你由是一般的意思。 JavaScript是非常面向事件的。所以,一开始,你要自动完成时关闭对话框关闭,因此答案的第一部分。当然,你可以把它绑定到一些间接的事件,如自动完成模糊或隐藏(你可能需要做皮自定义事件),但是,让你有点危险的,他们可能不会被触发,因为他们是间接

It depends what you mean by being "general". JavaScript is very much event-oriented. So, initially, you want autocomplete to close when dialog is closed, hence the first part of the answer. Sure you can bind it to some indirect events, such as autocomplete blur or hide (you may need to do a custom event for the hide), but that gives you a bit of risk that they might not be triggered, as they're indirect.

现在你想拖动对话框时,它关闭;好,这是不难要么;你可以用的dragstart 事件对话实现这一目标,但他们两个不同的事件,无论是在对话,而不是自动完成。我没有看到自动完成构件本身拖动对话框时,任何间接的事件。

Now you want it to close when dialog is dragged; well, that's not hard either; you can achieve this with the dragStart event for dialog, but they're two different events, both on dialogs, not autocomplete. I don't see any indirect event on autocomplete widget itself when dialog is dragged.

如果您的问题是指通过ID自动完成小部件,你可以使用一个基于上下文的选择,例如使用 $('。UI的自动完成输入',这一点),而不是 $('#标签')中对话框的事件处理程序。

If your issue is referring to the autocomplete widget by ID, you could use a context-based selector, e.g. use $('.ui-autocomplete-input', this) rather than $('#tags') in dialog's event handlers.

这篇关于JQuery的自动完成功能关闭选项时,单击外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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