【发布时间】:2017-01-07 19:18:01
【问题描述】:
您好,我想用angularjs 获取一个标签的值,我已经尝试过:
var photoName=angular.element('label[id=photoLbId]').val();
结果是不确定的,同时输入类型收音机正在工作
var ans1 = angular.element('input[name=answer1]:checked').val();
如何使用 angularjs 获取标签的 html 值? 这是标签的html代码:
<ul id="navlist" style="list-style: none; width: 1000px;">
<li ng-repeat="item in stepsUrlPhotosList track by $index" style="display: inline; width: 1000px;">
<label id="photoLbId" for="photoId">{{item.name}}</label>
<img id="photoId" style="width: 30%;max-height:300px ;" ng-src="{{item.photoUrl}}">
</li>
</ul>
这是来自角度代码的指令:
app.directive('quiz',['$http',function(answerList1) {
return {
restrict: 'AE',
scope: {},
templateUrl: 'template.html',
controller : ['$scope', '$http','answerList1',, function ($scope,$http,answerList1) {
$scope.checkAnswer1 = function() {
console.log('Checking elements..... '+angular.element('input[name=answer1]:checked').val());
var ans1 = angular.element('input[name=answer1]:checked').val();
console.log('Checking label.....'+angular.element('label[id=photoLbId]').val());
var photoName=angular.element('label[id=photoLbId]').val();
answerList1.push(photoName+' '+ ans1);
};
}]
}
}]);
【问题讨论】:
标签: angularjs