angularjs的ng-keyup事件
angular学习笔记02 angular指令大全
<input ng-keyup="event=$event">
//<p>event keyCode: {{ event.keyCode }}</p>
//<p>event altKey: {{ event.shiftKey }}</p>
myApp.directive(
'ngEnter'
,
function
() {
return
function
(scope, element, attrs) {
element.bind(
"keydown keypress"
,
function
(event) {
if
(event.which === 13) {
scope.$apply(
function
() {
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
在对应的控制器中的$scope上绑定一个shirtKeyCheck方法
$scope.shirtKeyCheck=
function
($event){
if
($event.keyCode==13){
//回车13,shift键为16
alert('按下了回车键');
}
}