1. 程式人生 > >如何用程式碼彈出Select框

如何用程式碼彈出Select框

不適用所有瀏覽器,經測試支援Chrome,IOS上的SAFARI

("#觸發點").click(function(e) {
            var element = $("#下拉框")[0], worked = false;
            if (document.createEvent) { // all browsers
                var e = document.createEvent("MouseEvents");
                e.initMouseEvent("mousedown", true, true, window, 0
, 0, 0, 0, 0, false, false, false, false, 0, null); worked = element.dispatchEvent(e); } else if (element.fireEvent) { // ie worked = element.fireEvent("onmousedown"); } if (!worked) { // unknown browser / error alert("It didn't worked in your browser."
); } });