在Focus上显示DropDown选项 [英] Display DropDown options on Focus
问题描述
我有一个简单的html下拉列表,如果可能的话,我想使用jQuery显示所有选项,如果此控件具有焦点(就像用户单击下拉列表一样)。我已经尝试过jQuery trigger(),点击(),以利用。
I have a simple html dropdown, I wants to use jQuery if possible to display all the options if this control has the focus(as if the user click on the dropdown). I have tried jQuery trigger(), click(), to avail.
<select id="single">
<option>Single</option>
<option>Single2</option>
</select>
推荐答案
由于表示下拉列表的UI元素 - list来自主机浏览器,它并不真正位于JS沙箱中 - 相反,我们只有一个DOM对象来表示我们可以操作的元素 - 选项列表,样式和选择的索引。交互内部元素的行为 - 扩展/折叠等发生在浏览器chrome级别 - 与制表符,文件菜单等相同 - 在JS沙箱之外。当DDL打开时,标准不会要求通知DOM,只有当它被聚焦时才会通知DOM。
Since the UI element that represents the drop-down-list comes from the host browser, it's not really inside the JS sandbox - rather, we merely have a DOM object that represents the things about the element we can manipulate - option list, style, and which index is selected. The behavior of interacting inside the element - expanding/collapsing, etc happens at the browser chrome level - same as tabs, file menu, etc. - outside the JS sandbox. The standard does not call for notifying the DOM when the DDL is opened, only when it is focused.
所以,简短回答 - 没有。
So, short answer - no.
这篇关于在Focus上显示DropDown选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!