打开焦点上的选择元素的下拉菜单
当 Select 元素获得焦点时,是否可以打开 Select 元素的下拉列表?
我知道当你点击它时它会自动聚焦......但我希望它在你点击它时也能工作。
Possible Duplicate:
How can you programmatically tell an HTML SELECT to drop down (for example, due to mouseover)?
Is it possible to open the drop down list of a Select element when the Select element gets focus?
I know it automatically focuses when you click it ... but I want it to work when you tab it too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,你的问题的答案只是“不,当前的 HTML 和 Javascript 控件不可能”
但是,如果你使用 jQuery 和这个插件(https://github.com/fnagel/jquery-ui/wiki/Selectmenu)对于选择菜单,我相信你可以这样做:
也是你的想法的另一种选择,但可能不那么花哨:
它所做的只是使其成为多行选择,所以在某种程度上它显示选项...
您可以在焦点上执行此操作,然后在单击时执行另一个事件,将其大小重置为 1 并停止事件传播(以便 onfocus 之后不会被调用..)
但就像我说的,这太专业了,所以要么按照你的选择方式生活,要么切换到 jQuery 选择菜单,并享受根据你的意愿动态打开和关闭它们的乐趣:)
Unfortunately the answer for your question is simply "No, its not possible with the current HTML and Javascript controls"
However, if you use jQuery and this plugin (https://github.com/fnagel/jquery-ui/wiki/Selectmenu) for select menus i believe you could do :
Also another alternative for your idea, but maybe not as fancy:
What this does is simply make it a multiline select, so in some way it displays the options...
You could do this on focus, and then do another event on click where you reset its size to 1 and stop the event propagation (so that onfocus doesn't get called after..)
but like i said, this is THAT professional, so either live with your select the way it is, or switch to jQuery select menus and have fun opening and closing them dynamically at your will :)
作为起点,如果使用 JQuery,您可以使用触发器函数,例如,如果您的选择框的 id 为“names”,只需调用 $('#names').trigger('click');
As a starting point, if using JQuery you could use the trigger function eg If your select box has an id of "names" simply call $('#names').trigger('click');