是否可以在激活时禁用选择选项?我有一个选择器,它有各种选项,每个选项触发一个SQL查询。如果两次选择相同的选项,则地图会中断。我认为最简单的解决方案是在选择后禁用选项。
<select id="sql" onclick="updateSource()" class="selector">
<option value="SELECT * FROM indicators WHERE 1=0" disabled selected>Select an Indicator</option>
<option value="SELECT * FROM indicators WHERE grain ILIKE 'Yes'">Change in grain (maize, wheat & barley) production</option>
<option value="SELECT * FROM indicators WHERE sorghum ILIKE 'Yes'">Change in Sorghum production</option>
</select>
答案 0 :(得分:2)
如果我理解正确,您希望在选择后禁用option
吗?
function updateSource(e) {
const target = e[e.value];
target.disabled = true;
}
&#13;
<select onchange="updateSource(this)">
<option value="0" disabled selected>Select an Indicator</option>
<option value="1">Change in grain (maize, wheat & barley) production</option>
<option value="2">Change in Sorghum production</option>
</select>
&#13;
或者它应该只禁用当前选择的那个吗?
function updateSource(e) {
Object.keys(e).forEach(k => e[k].disabled = false);
const target = e[e.value];
target.disabled = true;
}
&#13;
<select onchange="updateSource(this)">
<option value="0" disabled selected>Select an Indicator</option>
<option value="1">Change in grain (maize, wheat & barley) production</option>
<option value="2">Change in Sorghum production</option>
</select>
&#13;