diff --git a/examples/dropdown.html b/examples/dropdown.html index 51bd13b2..18203d6b 100644 --- a/examples/dropdown.html +++ b/examples/dropdown.html @@ -155,7 +155,10 @@ layui.use('dropdown', function(){ ,id: 'demo1' - //菜单被点击的事件 + // 触发点击事件的元素范围 --- default: 仅子菜单触发点击事件(默认,可不填); all: 所有父子菜单均触发点击事件 + ,clickScope: 'all' + + // 菜单被点击的事件 ,click: function(obj){ console.log(obj); } diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index bfaf1a12..7587f0e1 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -261,13 +261,15 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){ //触发菜单列表事件 that.elemView.find('.layui-menu li').on('click', function(e){ - var othis = $(this) - ,data = othis.data('item') || {} - ,isChild = data.child && data.child.length > 0; + var othis = $(this); + var data = othis.data('item') || {}; + var isChild = data.child && data.child.length > 0; + var isClickAllScope = options.clickScope === 'all'; // 是否所有父子菜单均触发点击事件 - if(!isChild && data.type !== '-'){ - that.remove(); + if((!isChild || isClickAllScope) && data.type !== '-'){ + isChild || that.remove(); typeof options.click === 'function' && options.click(data, othis); + layui.stope(e); } });