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


- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01