AngularJs在ng-click函数中如何获取代表当前元素的DOM对象

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <title></title>  
  5.     <script src="lib/jquery/jquery-1.10.2.min.js"></script>  
  6.     <script src="lib/angular/angular.min.js"></script>  
  7. </head>  
  8. <body ng-app>  
  9. <div ng-controller="TestCtrl">  
  10.     <a href data="1" ng-click="GoPage($event.target)">1</a>  
  11.     <a href data="2" ng-click="GoPage($event.target)">2</a>  
  12.     <a href data="3" ng-click="GoPage($event.target)">3</a>  
  13.     <a href data="4" ng-click="GoPage($event.target)">4</a>  
  14.     <a href data="5" ng-click="GoPage($event.target)">5</a>  
  15.     {{ page }}  
  16. </div>  
  17. <script>  
  18.     function TestCtrl($scope) {  
  19.         $scope.page = 1;  
  20.         $scope.getData = function () {  
  21.             console.log($scope.page);  
  22.         }  
  23.         $scope.GoPage = function (target) {  
  24.             $scope.page = target.getAttribute('data');  
  25.             this.getData();  
  26.         }  
  27.     }  
  28. </script>  
  29. </body>  
  30. </html>  

在Control中,angular.element()返回一个jquery对象,如angular.element(document).ready(function(){});

返回指定元素的scope

<code><span class="pln">angular</span><span class="pun">.</span><span class="pln">element</span><span class="pun">(</span><span class="pln">selector</span><span class="pun">).</span><span class="pln">scope</span><span class="pun">();</span></code>
posted @ 2017-04-01 11:06  品读夜的黑  阅读(6588)  评论(1编辑  收藏  举报