函数事件:
function layerOpen(title,url,fun_yes='',fun_cancel='',fun_end='',width='800px',height='70%')
{
var btns=false;
if(fun_yes)
{
var btns=['确认提交', '取消'];
}
var openId=layer.open({
type: 2,
title: title,
area: [width, height],
btn: btns,
maxmin: true,
shade: false,
shadeClose: false,
anim: 1,
content: url,
yes: function (index, layero) {
if (typeof fun_yes === "function"){
fun_yes(index, layero);
}
},
cancel: function (index, layero) {//取消事件
if (typeof fun_cancel === "function"){
fun_cancel(index, layero);
}
},
end: function () {//无论是确认还是取消,只要层被销毁了,end都会执行,不携带任何参数。layer.open关闭事件
if (typeof fun_end === "function"){
fun_end();
}
}
});
return openId;
}
前台调用:
var add;
$(".add").click(function(){
if(add){
$(".layui-layer-max").click();
return false;
}
add = layerOpen("添加菜单",'?act=add',function(index, layero){
//确认事件
//console.log(layero)
var iframe = $("#layui-layer-iframe"+index).html();
console.log(iframe)
//alert('123')
},function(index, layero){
//关闭事件
add='';
},function(){
//无论是确认还是取消,只要层被销毁了,end都会执行,不携带任何参数。layer.open关闭事件
});
});