<input type="text" ng-model="text1" ng-keyup="enterEvent($event)" />
<button ng-click="clickEvent()">确定按钮</button>
<script type="text/javascript">
var app = angular.module('myApp', []).controller('ctrl', function($scope){
$scope.clickEvent = function() {
// 响应事件
}
$scope.enterEvent = function(e) {
var keycode = window.event?e.keyCode:e.which;
if(keycode==13){
$scope.clickEvent();
}
}
</script>
另外一种写法
ng-keypress="($event.which === 13)?addTask():0"
网友评论