在一个div使用AngularJS ngKeyup,而不是输入 [英] Using AngularJS ngKeyup on a div rather than an input

查看:94
本文介绍了在一个div使用AngularJS ngKeyup,而不是输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了Plunker一些示例code:<一href=\"http://plnkr.co/edit/upExTHzpkwtZ45mdikFr?p=$p$pview\">http://plnkr.co/edit/upExTHzpkwtZ45mdikFr?p=$p$pview

I've set up a Plunker with some example code: http://plnkr.co/edit/upExTHzpkwtZ45mdikFr?p=preview

很简洁的问题是:我想要使用AngularJS NG-KEYUP 指令。在文档中我只看到在输入时,虽然我试图抓住关键presses页面上的任何地方,而不仅仅是内部的输入框。像这样:

The very succinct question is: I'm trying to use AngularJS' ng-keyUp directive. In the docs I've only seen is used on an input, although I'm trying to capture keypresses anywhere on the page rather than just inside an input box. Like so:

// view

<div ng-keyup="keyPress($event)">
     // The bulk of my controller's view goes in here
</div>

// inside controller

$scope.keyPress = function(e){
     console.log(e);
}

再次看到上面的Plunker一个例子。目前,它不会在所有的工作,并没有什么记录。我怎样才能得到它正常工作?

Again, see the Plunker above for an example. Currently, it doesn't work at all and nothing is logged. How can I get it to work properly?

推荐答案

尽量给div元素焦点,或使用的tabindex =1

Try to give the div element focus, or use tabindex="1"

这篇关于在一个div使用AngularJS ngKeyup,而不是输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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