首页 > 编程知识 正文

Layui 弹窗 回车执行确定按钮事件

时间:2023-05-04 15:12:51 阅读:203356 作者:2763

实现按 Enter 键关闭弹窗layer.open({ type: 1, content: 'Where is the love?', btn: ['确定'], success: function(layero, index){ this.enterConfirm = function(event){ if(event.keyCode === 13){ $(".layui-layer-btn0").click(); return false; //阻止系统默认回车事件 } }; $(document).on('keydown', this.enterConfirm); //监听键盘事件 // 点击确定按钮回调事件 $(".layui-layer-btn0").on("click",function() { console.log("peace and love"); }) }, end: function(){ $(document).off('keydown', this.enterConfirm); //解除键盘事件 }}); 实现按 Esc 键关闭弹窗layer.open({ type: 1, content: 'Where is the love?', btn: ['确定'], success: function(layero, index){ this.escQuit = function(event){ if(event.keyCode === 0x1B){ layer.close(index); console.log("peace and love"); return false; //阻止系统默认回车事件 } }; $(document).on('keydown', this.escQuit); //监听键盘事件 }, end: function(){ $(document).off('keydown', this.escQuit); //解除键盘事件 }});

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。