如何检查选择元素是否仍然“打开” /活跃与jQuery [英] How to check if an select element is still "open" / active with jquery

查看:152
本文介绍了如何检查选择元素是否仍然“打开” /活跃与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,如果选择表单元素此时处于活动状态,那么是否可以通过jQuery检测到?

我创建了这个小提琴来演示这个问题:

http://jsfiddle.net/E2PhT/2/



当您将鼠标悬停在搜索链接上时搜索表单显示出来。当你现在点击选择区域打开里面的选项,然后在没有选择任何东西的情况下,将表单保留在右侧(将鼠标移到灰色区域的右边缘),选择区域保持打开状态, eles消失了(它应该)。

现在我想要让select元素再次处于非活动状态,所以它不会保持打开状态,或者只要select元素阻止表单的其余部分消失仍然开放。

因此,无论如何,我必须以某种方式检测选择字段是否仍处于打开状态或处于活动状态。有没有什么办法可以用jQuery来检查这个状态?



Thx帮助。

解决方案您可以尝试:focus 选择器:

  if (!$(select)。is(:focus)){
// ...
}

DEMO: http:// jsfiddle。净/ E2PhT / 3 /

Is there anyway I can detect via jQuery if a select form element is active at the moment?

I created this fiddle to demonstrate the problem:

http://jsfiddle.net/E2PhT/2/

When you hover over the "Search"-Link the search form shows up. When you now click on the select-field to open the options inside and then, without choosing anything, leave the form on the right side (move the mouse past the right edge of the grey block), the select-field stays open while everything eles disappears (as it should).

Now I would like to either make the select element inactive again, so it doesn't stay open or prevent the rest of the form from disappearing as long as the select element is still open.

So either way I have to somehow detect if the select field is still open or active. Is there any way to check this state with jQuery?

Thx for help.

解决方案

You can try :focus selector:

if (!$("select").is(":focus")) {
    // ...
}

DEMO: http://jsfiddle.net/E2PhT/3/

这篇关于如何检查选择元素是否仍然“打开” /活跃与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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