detect key press on modal dialog not working(检测模态对话框上的按键不起作用)
问题描述
我想在显示模式时检测用户是否按下了任何键.我尝试了以下代码,但未触发事件.
I would like to detect whether the user has pressed any key when a modal is shown. I tried the following code but the events are not fired.
代码片段:
$("#modal_confirmation_dp_change").on('keydown keyup input', function ( e ) {
alert();
});
如果我尝试测试点击事件,它会被触发.
If I try to test click event, it is fired.
$("#modal_confirmation_dp_change").on('click', function ( e ) {
alert();
});
我正在使用 twitter 引导模式.我错过了什么吗?
I am using twitter bootstrap modal. Am I missing something?
回答:我找到了解决我的问题的方法.看来我不应该指向模态的 id 以便检测到按键事件.
ANSWER: I found the solution to my problem. It seems like I should not point to the id of the modal so that the keypress event will be detected.
推荐答案
我找到了解决问题的方法.看来我不应该指向模态的 id 以便检测到按键事件.
I found the solution to my problem. It seems like I should not point to the id of the modal so that the keypress event will be detected.
$(document).on('keydown keyup input click', function (e) {
if($('#modal_confirmation_dp_change').is(':visible')) {
var key = e.which;
if (key == 13) { //This is an ENTER
$('#changed_dp_ok').click();
}
}
});
这篇关于检测模态对话框上的按键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测模态对话框上的按键不起作用
基础教程推荐
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
