有没有办法打开选择选项onclick,而不是<select>
和<option>
元素?
<label onclick = 'openSelectOptions()'> Click Me </label>
答案 0 :(得分:0)
你可以尝试这个,但不适用于所有浏览器。 它适用于Google Chrome浏览器
function openSelectOptions(){
var element = $("#open")[0];
var worked = false;
if (document.createEvent) {
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) {
worked = element.fireEvent("onmousedown");
}
if (!worked) {
alert("It didn't worked in your browser.");
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="open">
<option>nothing</option>
<option>something</option>
<option>anything</option>
</select>
<button onclick = 'openSelectOptions()'> Click Me </button>
&#13;