javascript - 选择器 - 选择时暂时禁用选项
问题描述
是否可以在选择选项处于活动状态时禁用它?我有一个选择器,其中有各种选项,每个选项都会触发 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>
解决方案
如果我对您的理解正确,您想在option
它被选中后禁用它?
function updateSource(e) {
const target = e[e.value];
target.disabled = true;
}
<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>
还是应该只禁用当前选择的那个?
function updateSource(e) {
Object.keys(e).forEach(k => e[k].disabled = false);
const target = e[e.value];
target.disabled = true;
}
<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>
推荐阅读
- flutter - bloc state is the same after coming back to a page even though it was explicitly changed
- javascript - 使用 Angular 检索 firebase 实时数据
- regex - 带有 javascript 排序的正则表达式
- pm2 - 如何强制 PM2 使用我的应用程序的最新版本?
- python - 如何使用 python selenium 单击图像中的这些按钮之一(通知)
- flutter - 未处理的异常:无效的参数:“TextEditingController”的实例
- azure-sql-database - Azure SQL 数据库中的备份用户
- python - 烧瓶 - python - 降价到 html
- c# - 如何在c#中的按钮单击事件中调用参数化方法
- reactjs - 打字稿中反应组件中道具的简洁易读语法