Javascript jquery对话框的esc键事件
将jquery对话框的closeOnescape设置为false。要根据esc键触发事件,我如何实现它? 这也不管用Javascript jquery对话框的esc键事件,javascript,jquery,Javascript,Jquery,将jquery对话框的closeOnescape设置为false。要根据esc键触发事件,我如何实现它? 这也不管用 $(document).on("keypress","#popupid",function(e) { debugger; if (e.keycode === 27) { alert("esc key triggered"); } }); 用keyup功能替换keypress $(document)
$(document).on("keypress","#popupid",function(e) {
debugger;
if (e.keycode === 27) {
alert("esc key triggered");
}
});
用keyup功能替换keypress
$(document).on('keyup', function(e) {
if (e.keyCode === 27) { // escape key maps to keycode `27`
alert("esc key triggered");
}
});
说明:
$(文档)。按键(功能(e){
如果(e.keyCode==27){
//做smth
}});代码>调试器后放置警报;提醒(如keycode)并检查您使用的密码是否为27加上它的keycode*我发现问题,请使用keycode而不是keycode