【发布时间】:2018-10-12 07:42:32
【问题描述】:
我需要在文本框值的基础上选择复选框,例如:如果我在文本框中输入 5,然后我单击全选复选框,之后应该只选择表的前 5 行,否则它应该选择所有复选框。我如何使用 angularjs 来实现这一点,我附上了下面的代码,请仔细阅读
var app = angular.module('MyApp', [])
app.controller('MyController', function($scope) {
$scope.Customers = [{
CustomerId: 1,
Name: "John Hammond",
Country: "United States",
Selected: false
},
{
CustomerId: 2,
Name: "Mudassar Khan",
Country: "India",
Selected: false
},
{
CustomerId: 3,
Name: "Suzanne Mathews",
Country: "France",
Selected: false
},
{
CustomerId: 4,
Name: "Robert Schidner",
Country: "Russia",
Selected: false
},
{
CustomerId: 2,
Name: "Mudassar Khan",
Country: "India",
Selected: false
},
{
CustomerId: 3,
Name: "Suzanne Mathews",
Country: "France",
Selected: false
},
{
CustomerId: 2,
Name: "Mudassar Khan",
Country: "India",
Selected: false
},
{
CustomerId: 3,
Name: "Suzanne Mathews",
Country: "France",
Selected: false
}
];
$scope.CheckUncheckHeader = function() {
$scope.IsAllChecked = true;
for (var i = 0; i < $scope.Customers.length; i++) {
if (!$scope.Customers[i].Selected) {
$scope.IsAllChecked = false;
break;
}
};
};
$scope.CheckUncheckHeader();
$scope.CheckUncheckAll = function() {
for (var i = 0; i < $scope.Customers.length; i++) {
$scope.Customers[i].Selected = $scope.IsAllChecked;
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div ng-app="MyApp" ng-controller="MyController">
<table cellpadding="1" cellspacing="1" border="1">
<tr>
<th align="left">
<label>
<input type="checkbox" ng-model="IsAllChecked" ng-change="CheckUncheckAll()" />
CustomerId</label>
<br>
<input id="txtCheckCount" type="text" class="form-control input-sm" ng-model="chkCount" style="width: 45px;"></input>
</th>
<th>
Name
</th>
<th>
Country
</th>
</tr>
<tbody ng-repeat="m in Customers">
<tr>
<td>
<label for="chkCustomer_{{m.CustomerId}}">
<input id="chkCustomer_{{m.CustomerId}}" type="checkbox" ng-model="m.Selected" ng-change="CheckUncheckHeader()" />
{{m.CustomerId}}
</label>
</td>
<td>
{{m.Name}}
</td>
<td>
{{m.Country}}
</td>
</tr>
</tbody>
</table>
</div>
【问题讨论】:
-
I have attached below code please go through that- 恕我直言有点奇怪的说法......
标签: javascript c# jquery html asp.net