我想使用javascript触发组合框/选择框的鼠标按下事件。这是代码,它在crome中工作得很好,但在Firefox中却没有。对此有何帮助?
<select id="dropdown">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br>
<button id="fire" type="button" onclick="runThis()">Show dropdown items</button>
// <select> element displays its options on mousedown, not click.
showDropdown = function (element) {
var event;
event = document.createEvent('MouseEvents');
//event.initMouseEvent('mousedown', true, true, window);
event.initMouseEvent('mousedown', true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
element.dispatchEvent(event);
};
// This isn't magic.
window.runThis = function () {
var dropdown = document.getElementById('dropdown');
showDropdown(dropdown);
};
提前致谢....