活动开幕前一场select。 (点击速度不够快)
Event before the opening of a select. (click does not work fast enough)
我想在用户单击 select 时调用一个方法,就在选项列表出现之前。 (之后调用点击事件)
我想这样做是为了在用户看到之前修改选项列表。
有什么想法吗?
mousedown 和 focus 事件都允许您在打开下拉列表之前修改选项。
var el = document.getElementById("sel");
// Change focus to click or mousedown to see the difference
el.addEventListener("focus", modifyOpt, false);
function modifyOpt() {
var opts = sel.options;
opts[0].innerHTML = '2';
}
<select id="sel">
<option>1</option>
</select>
我想在用户单击 select 时调用一个方法,就在选项列表出现之前。 (之后调用点击事件)
我想这样做是为了在用户看到之前修改选项列表。
有什么想法吗?
mousedown 和 focus 事件都允许您在打开下拉列表之前修改选项。
var el = document.getElementById("sel");
// Change focus to click or mousedown to see the difference
el.addEventListener("focus", modifyOpt, false);
function modifyOpt() {
var opts = sel.options;
opts[0].innerHTML = '2';
}
<select id="sel">
<option>1</option>
</select>