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();
}
}
});
这篇关于检测模态对话框上的按键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测模态对话框上的按键不起作用


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01