angularjs的ng-keyup事件之回车事件

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>

<script src="angular.min.js"></script>
<script>
var myApp = angular.module("myApp", []);
    myApp.controller("testCtrl", function($scope){
        $scope.myClass = 'red';
        $scope.isClick = 'No!';
        $scope.myKeyup = function(e){
            var keycode = window.event?e.keyCode:e.which;
            if(keycode==13){
                $scope.myClass = 'green';
                $scope.myClick();
            }
        };
        $scope.myClick = function(){
            $scope.isClick = 'Yes!';
        };
    });
</script>
<style>
.red {color:red}
.green {color:green}
</style>
</head>

<body>
<div ng-app="myApp">
  <div ng-controller="testCtrl">
    <input ng-keyup="myKeyup($event)" type="text" />
    <ul>
      <li ng-click="myClick()" class="{{myClass}}">{{isClick}}</li>
    </ul>
  </div>
</div>
</body>
</html>
posted @ 2016-06-06 15:53  ShirleyHe  阅读(18119)  评论(0编辑  收藏  举报