优化 select 开启搜索时,在清空搜索框文本后重置选中项

This commit is contained in:
贤心 2023-02-16 00:29:01 +08:00
parent efbd528efe
commit 08dce68a70

View File

@ -503,8 +503,13 @@ layui.define(['lay', 'layer', 'util'], function(exports){
} }
}, 'keyup'); }, 'keyup');
// 当搜索值清空时
if(value === ''){ if(value === ''){
dl.find('.'+NONE).remove(); // 取消选中项
select.val('');
dl.find('.'+ THIS).removeClass(THIS);
(select[0].options[0] || {}).value || dl.children('dd:eq(0)').addClass(THIS);
dl.find('.'+ NONE).remove();
} }
followScroll(); // 定位滚动条 followScroll(); // 定位滚动条
@ -564,6 +569,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
$(document).off('click', hide).on('click', hide); // 点击其它元素关闭 select $(document).off('click', hide).on('click', hide); // 点击其它元素关闭 select
} }
// 初始渲染 select 组件选项
selects.each(function(index, select){ selects.each(function(index, select){
var othis = $(this) var othis = $(this)
,hasRender = othis.next('.'+CLASS) ,hasRender = othis.next('.'+CLASS)