0
I can move up and down with the keyboard keys but i cannot get the enter event correct角JS事件進入調用元素上的功能TR
**Controller**
$scope.myFunction = function()
{
alert('sadsad');
alert('hi');
}
**Also i added directive like this**
.directive('ngEnter', function()
{
restrict:'use strict';
return {
link: function (scope, elements, attrs) {
elements.bind('keydown keypress', function (event) {
if (event.which === 13) {
scope.$apply(function() {
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
}
};
});
**Below is the view code on which i m calling directive and function**
<tr class="find"ng-repeat="busServices in " ng-click="setSelected(busServices.bus_travel_id,this.busServices,$event)" ng-class="{selectedsd:busServices.bus_travel_id === idSelected}" ng-mouseover="ShowHideBoarding($event,this.busServices,true)" ng-mouseleave="ShowHideBoarding($event,false)" ng-init="($first) ? setSelected(busServices.bus_travel_id,this.busServices) : ''" ng-enter="myFunction()"></tr>
NG進入犯規被調用的。 我能做些什麼以便輸入可以工作。
基本上,如果您在任何輸入字段中使用ng-enter,它都可以工作。但是你在
也請查看您的指令的'restrict'選項。它不能'使用嚴格',它應該''A「'例如 – devnull69
可能重複[如何在AngularJS中使用按鍵事件?](http://stackoverflow.com/questions/17470790/how-to-使用-a -presspress-event-in-angularjs) –
回答
嘗試這樣的事情
的限制選項可以省略。
編輯:您將有一個屬性添加到您的
<tr>
,使他們可以集中並接收鑰匙*事件:與其他號碼取代0您更多的focussable
<tr>
來源
2017-04-10 12:02:19 devnull69
不工作,我想在tr上使用它 –
查看最新的編輯...至少你可以嘗試。通常'tr'元素並不意味着接收關鍵事件 – devnull69
不行不通 –
相關問題