Programmatic Invocation of HTML SELECT Drop-Down
Question:
Can HTML SELECT elements be programmatically opened, such as on mouseover events?
Answer:
While this functionality was once available in Chrome through HTML and Javascript, it has since been deprecated.
Historical Implementation (Chrome):
Prior to the deprecation, the following code allowed for the programmatic opening of SELECT drop-downs:
var event = document.createEvent('MouseEvents'); event.initMouseEvent('mousedown', true, true, window); element.dispatchEvent(event);
Current Status:
However, this approach no longer works. According to the W3C Working Draft for HTML5, Section 3.2.5.1.7, Interactive Content, elements with activation behaviors (such as keyboard, voice, or mouse input) should generally require user interaction to display options.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3