1、ng-click获得当前元素,不多说直接看示例代码
<!DOCTYPE html> <html> <head> <title></title> <script src="lib/jquery/jquery-1.10.2.min.js"></script> <script src="lib/angular/angular.min.js"></script> </head> <body ng-app> <div ng-controller="TestCtrl"> <a href data="1" ng-click="GoPage($event.target)">1</a> <a href data="2" ng-click="GoPage($event.target)">2</a> <a href data="3" ng-click="GoPage($event.target)">3</a> <a href data="4" ng-click="GoPage($event.target)">4</a> <a href data="5" ng-click="GoPage($event.target)">5</a> {{ page }} </div> <script> function TestCtrl($scope) { $scope.page = 1; $scope.getData = function () { console.log($scope.page); } $scope.GoPage = function (target) { $scope.page = target.getAttribute('data'); this.getData(); } } </script> </body> </html>
2、angular.element()用法
在Control中,angular.element()返回一个jquery对象,如angular.element(document).ready(function(){});
所以你可以对她做你对所有jquery对象可以做的事
3、返回指定元素的scope:
varsidebar=document.getElementsById('sidebar');varscope=angular.element(sidebar).scope();原文链接:https://www.f2er.com/angularjs/147433.html