layer弹窗 绑定回车关闭事件
1、来源:http://fly.layui.com/jie/5202/
layer.open({
title: '回车关闭测试'
,content: '我是内容'
,btn: ['确认','关闭']
,success: function(layero, index){
this.enterEsc = function(event){
if(event.keyCode === 13){
layer.close(index);
return false; //阻止系统默认回车事件
}
};
$(document).on('keydown', this.enterEsc); //监听键盘事件,关闭层
}
,end: function(){
$(document).off('keydown', this.enterEsc); //解除键盘关闭事件
}
});
2、来源:http://blog.csdn.net/donkeymini/article/details/70241029
function showSureDialog() {
let index = layer.open({
skin: "demo-class1",
btn: ['确定','取消'],
yes: function(index, layero){
deleteFile(index)
},
title: "确认信息",
area: ["315px", "160px"],
content: "执行后不可恢复,确定删除此文件吗?",
// ++enter
success: function(layero, index){
$(document).on('keydown', function(e){ //document为当前元素,限制范围,如果不限制的话会一直有事件
if(e.keyCode == 13){
deleteFile(index);
}
})
}
// ++
});
}