jQuery UI 自动完成:确定搜索窗口是否打开?
我想在输入的 onclick 事件中触发搜索,但前提是搜索窗口尚未打开。目前,我这样做:
$(this).bind('click.ajaxselect', function(e) {
if(!$(this).autocomplete('widget').is(':visible')) {
$(this).autocomplete('search','');
}
});
但我不太喜欢使用 :visible
选择器,因为它也会搜索所有父项。有什么财产我可以检查吗?
对话框有这个 isOpen
方法,自动完成功能是否有类似的东西?
I want to trigger a search in the onclick event of my input, but only if the search window isn't already open. Presently, I do this:
$(this).bind('click.ajaxselect', function(e) {
if(!$(this).autocomplete('widget').is(':visible')) {
$(this).autocomplete('search','');
}
});
But I'm not overly fond of using the :visible
selector because it searches up through all the parents as well. Is there some property I can check?
Dialog has this isOpen
method, does autocomplete have something similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置一个简单的变量并不难:
那么你的监听器就很简单:
Wouldn't be hard to set a simple variable:
Then your listener is easy:
我参加聚会已经很晚了,但我有一个替代的、更高效的解决方案。由于需要做的只是检查 CSS 属性的值,因此使用状态变量和两个事件处理程序来更新所述变量似乎是一个非常繁重(并且可能很脆弱)的解决方案。我觉得这种编码风格使得 javascript 驱动的网络的某些部分显得迟缓,尽管我们现在拥有巨大的计算能力。但我离题了。
您可以像这样测试 CSS
display
属性:为了完整起见,以下是如何在“上下文无关”函数中实现此类检查:
I'm pretty late to the party, but I have an alternative, more performant solution to this. Since all that needs to be done is check the value of a CSS attribute, using a state variable and two event handlers to update said variable seems like a very heavy (and possibly brittle) solution. I feel that this style of coding is what makes parts of the javascript-driven web feel sluggish, even though we're provided with enormous computing power nowadays. But I digress.
You can test for the CSS
display
attribute like this:For completeness, here's how to implement such a check in a "context-free" function: