mirror of https://github.com/layui/layui
新增 dropdown 的 clickScope 属性
parent
4cbd1e5c0d
commit
cf2531947c
|
@ -155,6 +155,9 @@ layui.use('dropdown', function(){
|
||||||
|
|
||||||
,id: 'demo1'
|
,id: 'demo1'
|
||||||
|
|
||||||
|
// 触发点击事件的元素范围 --- default: 仅子菜单触发点击事件(默认,可不填); all: 所有父子菜单均触发点击事件
|
||||||
|
,clickScope: 'all'
|
||||||
|
|
||||||
// 菜单被点击的事件
|
// 菜单被点击的事件
|
||||||
,click: function(obj){
|
,click: function(obj){
|
||||||
console.log(obj);
|
console.log(obj);
|
||||||
|
|
|
@ -261,13 +261,15 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
|
||||||
|
|
||||||
//触发菜单列表事件
|
//触发菜单列表事件
|
||||||
that.elemView.find('.layui-menu li').on('click', function(e){
|
that.elemView.find('.layui-menu li').on('click', function(e){
|
||||||
var othis = $(this)
|
var othis = $(this);
|
||||||
,data = othis.data('item') || {}
|
var data = othis.data('item') || {};
|
||||||
,isChild = data.child && data.child.length > 0;
|
var isChild = data.child && data.child.length > 0;
|
||||||
|
var isClickAllScope = options.clickScope === 'all'; // 是否所有父子菜单均触发点击事件
|
||||||
|
|
||||||
if(!isChild && data.type !== '-'){
|
if((!isChild || isClickAllScope) && data.type !== '-'){
|
||||||
that.remove();
|
isChild || that.remove();
|
||||||
typeof options.click === 'function' && options.click(data, othis);
|
typeof options.click === 'function' && options.click(data, othis);
|
||||||
|
layui.stope(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue