From 397cf80f7cc72d99b8fe5ea842ada78341b788c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Mon, 18 Jul 2022 00:01:27 +0800 Subject: [PATCH] update --- examples/laydate.html | 8 +++++++- src/modules/laydate.js | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/laydate.html b/examples/laydate.html index 01857051..a7e2e8e7 100644 --- a/examples/laydate.html +++ b/examples/laydate.html @@ -257,13 +257,19 @@ layui.use('laydate', function(laydate){ } }); - //同时绑定多个 + // 同时绑定多个 + laydate.render({ + elem: '.test-item', + trigger: 'click' + }); + /* lay('.test-item').each(function(){ laydate.render({ elem: this ,trigger: 'click' }); }); + */ //自定义重要日 var ins555 = laydate.render({ diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 28629e8d..72f2ec8a 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -74,6 +74,17 @@ var that = this; that.index = ++laydate.index; that.config = lay.extend({}, that.config, laydate.config, options); + + // 若 elem 非唯一,则拆分为多个实例 + var elem = lay(options.elem || that.config.elem); + if(elem.length > 1){ + layui.each(elem, function(){ + laydate.render(lay.extend({}, that.config, { + elem: this + })); + }); + return that; + } //初始化 id 参数 options = that.config; @@ -1292,7 +1303,7 @@ ); }; - //获得指定日期时间对象时间戳 + // 获得指定日期时间对象的毫秒数 Class.prototype.getDateTime = function(obj){ return this.newDate(obj).getTime(); } @@ -1773,8 +1784,9 @@ // 关闭日期面板 laydate.close = function(id){ - var elem = lay('#'+ (id ? ('layui-laydate'+ id) : Class.thisElemDate)); - elem.remove(); + var that = thisModule.getThis(id || laydate.thisId); + if(!that) return; + return that.remove(); }; //加载方式