login
欢迎访问QkqBeer博客园!

angularJS键盘响应事件

<!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 @ 2018-07-18 11:34  BeerQkq  阅读(690)  评论(0编辑  收藏  举报