检测HTML select元素是否已展开(无需手动跟踪状态) [英] Detect if an HTML select element is expanded (without manually tracking state)

查看:310
本文介绍了检测HTML select元素是否已展开(无需手动跟踪状态)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测下拉是否扩大。我不想使用额外的事件处理程序进行点击/鼠标悬停等因为下拉菜单是动态的,并且由于其他原因我不能使用像jQuery live这样的东西。基本上我想要一些可以给出任意 select 元素(没有其他附加的事件处理程序,类等)的东西,可以给出关于它是否被扩展的真/假答案或者没有。

I'd like to detect if a drop down is expanded or not. I don't want to use extra event handlers for click/mouseover etc because the drop-downs are dynamic and for other reasons I can't use something like jQuery live. Basically I'd like something that can given an arbitrary select element (no other attached event handlers, classes, etc), can give a true/false answer on whether it is expanded or not.

对于我的特定应用程序,我正在处理鼠标滚轮事件,但是当打开下拉菜单时会不想处理它们(这会覆盖浏览器默认功能)。但是,当鼠标悬停在 select 上时,我仍然想要处理鼠标滚轮事件,但是还没有打开它。

For my specific application, I am handling mouse wheel events, but don't want to handle them when a drop down is open (which would override the browser default functionality). However, I still want to handle the mouse wheel events when the mouse has hovered over the select, but has not opened it.

推荐答案

我之前看过这个,出于类似的原因。除了尝试手动跟踪它之外我永远找不到解决方案,这实际上是行不通的。有几种方法可以打开/关闭选择(下拉),例如Alt + Dn Arrow。如果用户点击浏览器外部的内容,则会关闭打开的选择。试图跟踪选择的状态是徒劳的。除非别人带来我在追捕时遗漏的东西,否则你必须尽可能优雅地编码。

I looked into this before, for similar reasons. I could never find a solution other than trying to track it manually which really doesn't work. There are several ways to open/close a select (drop down) such as Alt+Dn Arrow. An open select will close if the user clicks on something outside the browser. Trying to keep track of the state of the select is an exercise in futility. Unless someone else comes along with something I missed on my hunt, you'll have to code around it as elegantly as you can.

这篇关于检测HTML select元素是否已展开(无需手动跟踪状态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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