优化 lay 构造器,以适配选择器为自身对象的情况

pull/1220/head
贤心 2023-03-27 12:24:32 +08:00
parent 8de9a9c043
commit 365b159a18
1 changed files with 8 additions and 5 deletions

View File

@ -12,12 +12,15 @@
return new LAY(selector); return new LAY(selector);
} }
//DOM构造器 // DOM 构造器
,LAY = function(selector){ ,LAY = function(selector){
var index = 0 var index = 0;
,nativeDOM = typeof selector === 'object' ? [selector] : ( var nativeDOM = typeof selector === 'object' ? function(){
this.selector = selector // 仅适配简单元素对象
,document.querySelectorAll(selector || null) return layui.isArray(selector) ? selector : [selector];
}() : (
this.selector = selector,
document.querySelectorAll(selector || null)
); );
for(; index < nativeDOM.length; index++){ for(; index < nativeDOM.length; index++){
this.push(nativeDOM[index]); this.push(nativeDOM[index]);