可以jQuery告诉是否< select>的< option>元素当前显示? [英] Can jQuery tell if the <option>s of a <select> element are currently displayed?

查看:75
本文介绍了可以jQuery告诉是否< select>的< option>元素当前显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我的客户希望我显示一些简单的说明一旦用户以使得< option> 列表的方式与我们的< select> 元素交互我想,如果在< select> 框下面没有太多空间,一些浏览器向上打开,则下拉(或下拉然后,一旦用户做出新的选择并因此导致选项列表消失,或者如果他们简单地关闭选项列表而不进行改变,则指令将再次消失。

My customer would like me to display some simple instructions once the user interacts with our <select> element in such a way as to cause the <option> list to drop down (or "drop up", I suppose, since some browsers open upwards if there is not much room beneath the <select> box). And then the instructions should disappear again once the user has either made a new selection and thus caused the option list to disappear, or if they simply close the option list without making a change.

我以为我在使用CSS / CSS3选择器和jQuery事件使得类似< div> 的指令出现和消失时有相当丰富的经验,但是对于这种情况,我无法确定是否有一种方法来告诉< select> 框不仅仅是活动或专注当选择框仍然关闭并且不显示其选项列表 - 但实际上是打开时,可以是真的。没有我已经测试的CSS伪选择器或jQuery事件让我看到,更少响应,< select> 的开放状态或闭合状态, code>框。

I thought that I was fairly well-experienced with using both CSS/CSS3 selectors and jQuery events to make things like a <div> full of instructions appear and disappear, but for this case I am having trouble figuring out whether there is a way to tell when a <select> box is not merely "active" or "focused" — both of which can be true while the select box is still closed and not displaying its list of options — but actually open. None of the CSS pseudo-selectors or jQuery events that I have tested let me "see", much less respond to, the state of the open-ness or closed-ness of the <select> box.

有没有人知道如何设置触发器或写一个CSS规则,取决于当前是否显示选项列表?

Does anyone know how I can set a trigger or write a CSS rule that depends on whether the options list is currently displayed?

推荐答案

如果 $('myID:focus') ,还有另一种方法。

If $('myID:focus') is not sufficient, I doubt, that there is another way.

这篇关于可以jQuery告诉是否&lt; select&gt;的&lt; option&gt;元素当前显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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