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.
The above is the detailed content of Can HTML SELECT Dropdowns Be Programmatically Opened?. For more information, please follow other related articles on the PHP Chinese website!