开发者

How can you tell if an HTML dropdown is displaying the list of options

Is there a way to determine if a given drop down is currently active and displaying it's list of options?

I am currently binding to t开发者_运维技巧he mousedown event of the dropdown and populating the options when the user clicks on it. Unfortunately the mousedown event fires when the user selects the option as well.

If I can determine if the drop down is already displaying it's options, then I can skip populating the options.


This will tell you if the select element has options in it

In javascript

document.getElementById("mySelectElementId").options.length

In JQuery

$("#mySelectElementId")[0].options.length

Edited: OK instead of using the mousedown event try using the focus event on the select element. This will also ensure that you populate the control properly when a user uses tab to get to the select element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜