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

pull/1203/head
贤心 2023-02-16 00:29:01 +08:00
parent efbd528efe
commit 08dce68a70
1 changed files with 7 additions and 1 deletions

View File

@ -503,8 +503,13 @@ layui.define(['lay', 'layer', 'util'], function(exports){
}
}, 'keyup');
// 当搜索值清空时
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(); // 定位滚动条
@ -564,6 +569,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
$(document).off('click', hide).on('click', hide); // 点击其它元素关闭 select
}
// 初始渲染 select 组件选项
selects.each(function(index, select){
var othis = $(this)
,hasRender = othis.next('.'+CLASS)