diff --git a/docs/dropdown/detail/options.md b/docs/dropdown/detail/options.md index 4f533019..5a88c7b5 100644 --- a/docs/dropdown/detail/options.md +++ b/docs/dropdown/detail/options.md @@ -302,6 +302,20 @@ click: function(data, othis){ 用法详见:[#示例](#examples) + + + +close 2.9.7+ + + +面板关闭后的回调函数。返回的参数如下: + +``` +close: function(elem){ + console.log(elem); // 当前组件绑定的目标元素对象 +} +``` + diff --git a/examples/dropdown.html b/examples/dropdown.html index 386db7be..f22ea4d4 100644 --- a/examples/dropdown.html +++ b/examples/dropdown.html @@ -37,225 +37,286 @@ diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 7510b663..c92506fd 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -377,14 +377,19 @@ layui.define(['jquery', 'laytpl', 'lay', 'util'], function(exports){ Class.prototype.remove = function(){ var that = this; var options = that.config; - var elemPrev = thisModule.prevElem; + var prevContentElem = thisModule.prevElem; // 若存在已打开的面板元素,则移除 - if(elemPrev){ - elemPrev.data('prevElem') && ( - elemPrev.data('prevElem').data(MOD_INDEX +'_opened', false) - ); - elemPrev.remove(); + if(prevContentElem){ + var prevId = prevContentElem.attr('lay-id'); + var prevTriggerElem = prevContentElem.data('prevElem'); + var prevInstance = thisModule.getThis(prevId); + var prevOnClose = prevInstance.config.close; + + prevTriggerElem && prevTriggerElem.data(MOD_INDEX +'_opened', false); + prevContentElem.remove(); + delete thisModule.prevElem; + typeof prevOnClose === 'function' && prevOnClose.call(prevInstance.config, prevTriggerElem); } lay('.' + STR_ELEM_SHADE).remove(); };