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(‘按下了回车键‘);
}
}
时间: 2024-11-08 06:36:41