HTML:
<form role="form" ng-submit="submit3(qgradecontainer)">
<div data-ng-repeat="qgrade in qgradecontainer">
<div class="form-group">
<label>Quiz #{{array[$index]}}</label>
</div>
<div class="form-group">
<label>Correct Answers</label>
<input type="number" min="0" max="{{array2[$index]}}" class="form-control" placeholder="Number of items: {{array2[$index]}}" ng-model="qgrade.score" id="sc{{$index}}">
</div>
</div>
<div class="text-center">
<input type="submit" class="btn btn-success" value="Save">
</div>
</form>
控制器:
gradingSheetSrvc.getNumOfitems($scope.qtbl).then(function(msg){
if(msg.data){
$scope.array2 = $.map(msg.data[0], function(value, index) {
return [value];
});
$scope.ind = $.map(msg.data[0], function(value, index) {
return [index];
});
//console.log($scope.array2[1]);
for(var i=1; i<=len; i++){
$scope.qgradecontainer.push({'id':$scope.array[i-1],'sid':id,'col':$scope.ind[i-1],'tbl':$scope.qtbl,'numofitems':$scope.array2[i-1]});
document.getElementById("sc"+i--).value = "Test";
}
}
});
有没有办法用这段代码在输入文本中放置文本?因为我试图在我的控制器内的输入中使用document.getElementById("sc").value
放置文本,但我总是收到一条错误消息,指出Cannot set property 'value' of null
答案 0 :(得分:0)
首先,你永远不应该在控制器中操纵DOM,如果你想设置像;
这样的值<input type="number" value="100">
其他一切都保持不变只需将value属性设置为您想要的值