From 9f20b0f441944b6835bf8cacf66def91e807322f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 2 Mar 2023 00:12:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20`tab`=20=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8B=E6=A0=87=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/element.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/element.js b/src/modules/element.js index 1a46f82e..e4c7a53e 100644 --- a/src/modules/element.js +++ b/src/modules/element.js @@ -110,19 +110,25 @@ layui.define('jquery', function(exports){ // 基础事件体 var call = { - //Tab 点击 + // Tab 点击 tabClick: function(e, index, liElem, options){ options = options || {}; - index = index === undefined - ? othis.parent().children('li').index(othis) - : index; var othis = liElem || $(this); - var parents = options.headerElem ? othis.parent() : othis.parents('.layui-tab').eq(0); - var item = options.bodyElem ? $(options.bodyElem) : parents.children('.layui-tab-content').children('.layui-tab-item'); + var parents = options.headerElem + ? othis.parent() + : othis.parents('.layui-tab').eq(0); + var item = options.bodyElem + ? $(options.bodyElem) + : parents.children('.layui-tab-content').children('.layui-tab-item'); var elemA = othis.find('a'); var isJump = elemA.attr('href') !== 'javascript:;' && elemA.attr('target') === '_blank'; //是否存在跳转 var unselect = typeof othis.attr('lay-unselect') === 'string'; //是否禁用选中 var filter = parents.attr('lay-filter'); + + // 下标 + index = index === undefined + ? othis.parent().children('li').index(othis) + : index; //执行切换 if(!(isJump || unselect)){