Select组件选项隐显时加载延迟,首次点击显示异常问题
首次点击select组件显示异常

第二次点击select组件显示正常

绑定的点击事件代码
$(document).on("click", "#edit_afpDetalle_mes", function () { actualizarSelectsMes('#edit_tabla_afp_detalle'); }); $(document).on("click", "#btnEliminarFilaEdit", function () { eliminarFila(this); });
处理select选项的函数代码
function actualizarSelectsMes(id_input) { // 获取现有行中已选中的所有月份 var mesesSeleccionados = []; document.querySelectorAll(id_input + ' tbody select').forEach(function (select) { if (select.value !== '') { mesesSeleccionados.push(select.value); } }); // 更新表格中的每个select组件 document.querySelectorAll(id_input).forEach(function (select) { select.querySelectorAll('option').forEach(function (option) { // 若该选项已在其他select中被选中,则隐藏它 if (mesesSeleccionados.includes(option.value) && option.value !== select.value) { option.style.display = 'none'; } else { option.style.display = 'block'; } }); }); }
select组件应显示如第二张图中的正常效果,但首次点击时存在延迟:所有选项先全部显示,随后已选中的选项才快速隐藏。
内容的提问来源于stack exchange,提问作者Jorge Mantilla
相关产品推荐
相关产品推荐

