0
我想用javascript觸發組合框/選擇框的鼠標按下事件。這裏是代碼,它在crome中完美工作,但不在Firefox中。對此有何幫助?如何在firefox中使用javascript來觸發鼠標事件?
<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);
};
在此先感謝....
是'element.click()'不夠好? – 2012-10-30 11:48:54
@ H2CO3 - 不,我想要的是,當用戶點擊下拉某個選項,然後它加載數據在這裏,並選擇該選項,但我想保持下拉下來打開.. 比較這在克羅姆和FF和看到區別: http://jsfiddle.net/fz2sY/106/ – CPP
我有同樣的問題,找不到任何東西!從什麼時候開始,在Firefox中沒有'mousedown'工作? – WebWanderer