ng-click得到当前元素,
直接上代码:
<!DOCTYPE html> <html> <head> <title></title> <script src="../plugins/jquery/jquery.js"></script> <script src="../plugins/angular/angular.js"></script> </head> <body ng-app="AngularApp"> <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> var _app=angular.module("AngularApp",[]); function TestCtrl($scope) { $scope.page = 1; $scope.getData = function () { console.log($scope.page); } $scope.GoPage = function (target) { $scope.page = target.getAttribute('data'); this.getData(); } } _app.controller("TestCtrl",TestCtrl); </script> </body> </html>
其中:target获取到的是点击对象的html字符串,可以通过jquery中$(target)这种形式将字符串转换为dom对象。然后就可以随意进行操作啦。