我有五个列的行中有多个文本框,默认情况下禁用这些文本框,如果我选中与该特定行对应的复选框,则应启用这些文本框。使用以下代码,我可以通过仅选中第一个复选框来启用所有文本框。但我需要为每一行进行单独的操作。
我的控制器代码:
$scope.checkEnable = function () {
console.log($('#check').prop('checked'));
$scope.enableText = !$('#check').prop('checked');
};
HTML:
<div class="row item-head" ng-repeat="item in area track by $index">
<div class="col-md-4 col-xs-4 check-box">
<input type="checkbox" id='check' ng-model="check" ng-change="checkEnable()" /> {{item.servicename}}
</div>
<div class="col-md-8 col-xs-8">
<div class="row">
<div class="col-md-2 col-xs-2"></div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="enableText" />
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="enableText" />
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="enableText" />
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="enableText" />
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="enableText" />
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
在这种情况下,你甚至不需要控制器(当然也避免使用jQuery)。您只需像ng-disabled="check"
一样使用ngDisabled:
<div class="row item-head" ng-repeat="item in area track by $index">
<div class="col-md-4 col-xs-4 check-box">
<input type="checkbox" ng-model="check"> {{item.servicename}}
</div>
<div class="col-md-8 col-xs-8">
<div class="row">
<div class="col-md-2 col-xs-2"></div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="check">
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="check">
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="check">
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="check">
</div>
<div class="col-md-2 col-xs-2">
<input type="text" class="form-data" ng-disabled="check">
</div>
</div>
</div>
</div>