单击页面上的文档按键不起作用? [英] keydown on document is not working when clicked on page?

查看:113
本文介绍了单击页面上的文档按键不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

I am using

$(document).keydown(function (event) {
  alert(event.keyCode);
});


现在,当我单击页面的任何部分,然后按任意键时,此事件不会触发,并且不会发出警报.

为什么?


This function works great when the page is loaded..Now when i click on any part of the page and then when i press any key this event is not firing and alert does not come..

Why?

推荐答案

(文档).keydown( function (事件){ 警报(event.keyCode); });
(document).keydown(function (event) { alert(event.keyCode); });


现在,当我单击页面的任何部分,然后按任意键时,此事件不会触发,并且不会发出警报.

为什么?


This function works great when the page is loaded..Now when i click on any part of the page and then when i press any key this event is not firing and alert does not come..

Why?


尝试窗口


(窗口).keydown(功能(事件){ 警报(event.keyCode); });
(window).keydown(function (event) { alert(event.keyCode); });


这篇关于单击页面上的文档按键不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆