按键事件在“输入"之外停止工作更新到 0.5.2 后 Meteor 中的元素 [英] Keypress events stopped working outside of "input" elements in Meteor after update to 0.5.2

查看:40
本文介绍了按键事件在“输入"之外停止工作更新到 0.5.2 后 Meteor 中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现在升级到 Meteor 0.5.2(从 0.5 起)后,关键事件('keypress'、'keydown'、keyup')的事件处理对我来说停止工作了.其他事件,如 ('click' & 'blur') 工作得很好.

I just found out that after upgrading to Meteor 0.5.2 (from 0.5) event handling for key events ('keypress', 'keydown', keyup') stopped working for me. Other events like ('click' & 'blur') work just fine.

即使在示例应用中,这样的代码也没有任何作用:

Even in sample apps the code like this doesn't do anything:

Template.someTemplate.events = {
  'keydown' : function(e) {
      console.log(e);
  }
};

有趣的是,这段代码确实工作(函数触发)用于我在 input type="text" 中输入的按键文本区域.但在其他地方 - 什么也没有发生.

The interesting thing is that this code does work (function fires) for keypresses in I'm typing inside an input type="text" or a textarea. But elsewhere - nothing happens.

我正在 Ubuntu 12.10 中对最新的 Crome 进行测试.

I'm testing on the latest Crome in Ubuntu 12.10.

有其他人遇到过这个问题吗?

Has anybody else experienced the issue?

谢谢,乔治

推荐答案

keydown 事件适用于可编辑的 html.输入字段或 contenteditable 标签会触发 keydown 事件.

The keydown event works for me for html that is editable. Input fields or contenteditable tags fire the keydown event.

但如果您要问如何处理 body 上的 keydown 事件,此线程可能会有所帮助:

But if you're asking how to handle keydown events on the body, this thread might help:

你可以看看这个帖子:https://groups.google.com/forum/?fromgroups=#!topic/meteor-talk/uHy--xIGH8o.

You can take a look at this thread: https://groups.google.com/forum/?fromgroups=#!topic/meteor-talk/uHy--xIGH8o.

基本上,就目前而言,您可以直接将事件处理程序附加到 body 元素.在上面链接的例子中,他等待模板渲染完成,然后使用jQuery附加处理程序:

Basically, for now, you can attach an event handler to the body element directly. In the example in the above link, he waits until the template is rendered, and then used jQuery to attach the handler:

Template.myTemplate.rendered = function() { 
        // Assuming you're using jQuery 
        $('body').on('keydown',function() { 
                console.log('key pressed'); 
        }); 
} 

Meteor 团队显然将很快为附加身体级事件提供更好的支持.

The Meteor team is apparently going to include better support for attaching body level events soon.

这篇关于按键事件在“输入"之外停止工作更新到 0.5.2 后 Meteor 中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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