我正在尝试获取所单击锚点的直接父级的属性值。关于如何实现此目标的任何想法。我的代码如下所示:
HTML
<div class="perTalk" catch="1">
<div>Content one</div>
<a href="#" ng-click="idVal()">Reply</a>
</div>
<div class="perTalk" catch="1.1">
<div>Content two</div>
<a href="#" ng-click="idVal()">Reply</a>
</div>
<div class="perTalk" catch="1.2">
<div>Content three</div>
<a href="#" ng-click="idVal()">Reply</a>
</div>
AngularJS
var app = angular.module('myApp', []);
app.controller('../scripts/sleek-angular-control', function ($scope) {
$scope.idVal = function () {
var catchVal = $(this).closest(".perTalk").attr("catch");
$scope.firstname = catchVal;
$scope.lastname = "Doe";
}
});