From d74abb453cb45ea5d2eb69f0ed7250caf0ab0088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 19 Nov 2023 16:38:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20`util.on()`=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=8F=90=E5=8D=87=E5=8F=82=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E7=81=B5=E6=B4=BB=E6=80=A7=E5=92=8C=E4=BB=A3=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/util.js | 72 +++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/src/modules/util.js b/src/modules/util.js index ae0bd577..2632ef7d 100644 --- a/src/modules/util.js +++ b/src/modules/util.js @@ -383,33 +383,61 @@ layui.define('jquery', function(exports){ } }, - // 批量事件 - event: function(attr, obj, eventType){ - var _body = $('body'); - eventType = eventType || 'click'; - - // 记录事件回调集合 - obj = util.event[attr] = $.extend(true, util.event[attr], obj) || {}; - - // 清除委托事件 - util.event.UTIL_EVENT_CALLBACK = util.event.UTIL_EVENT_CALLBACK || {}; - _body.off(eventType, '*['+ attr +']', util.event.UTIL_EVENT_CALLBACK[attr]) - - // 绑定委托事件 - util.event.UTIL_EVENT_CALLBACK[attr] = function(){ - var othis = $(this); - var key = othis.attr(attr); - (typeof obj[key] === 'function') && obj[key].call(this, othis); - }; + /** + * 批量事件 + * @param {string} [attr="lay-on"] - 触发事件的元素属性名 + * @param {Object.