2016-04-15 52 views
0

所以,我有一个表有多行。我试图用按钮选择每一行;此外,在表格标题中,还有一个全选按钮,用于选择所有行中的所有按钮。这里是html:创建“全选”按钮来选择所有按钮

<table class="table" ng-controller="myController"> 
    <thead> 
    <tr class="info"> 
     <th>Company Name</th> 
     <th>Address</th> 
     <th> 
     <input type="button" class="btn btn-default" id="select-all" data-toggle="button" value="Show All" aria-pressed="false"> 
     </th> 
    </tr> 
    </thead> 
    <tbody ng-repeat="company in fieldData"> 
    <tr> 
    <td>{{ company.name }}</td> 
    <td>{{ company.address }}</td> 
    <td style="text-align: center"> 
     <input type="button" class="btn btn-default" id="select-one" data-toggle="button" value="Show" aria-pressed="false"> 
    </td> 
    </tr> 
    </tbody> 
</table> 

我怎样才能使用jQuery来改变所有行的阿里亚按下的值的函数?有任何想法吗?

+0

是的。通过按#选择全部按钮将#个选择按钮更改为aria-pressed =“true”。 – jake

+0

您使用的角度,这将生活在一个指令? – ste2425

+0

这些按钮的默认值是“false”。 – jake

回答

0

您使用的是Angular js。

我写一个简单的代码,看看

<div> 
<ul ng-controller="checkboxController"> 
    <li>Check All 
     <input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" /> 
    </li> 
    <li ng-repeat="item in Items"> 
     <label>{{item.Name}} 
      <input type="checkbox" ng-model="item.Selected" /> 
     </label> 
    </li> 
</ul> 

angular.module("CheckAllModule", []) 
.controller("checkboxController", function checkboxController($scope) { 

角代码在这里

$scope.Items = [{ 
    Name: "Item one" 
}, { 
    Name: "Item two" 
}, { 
    Name: "Item three" 
}]; 
$scope.checkAll = function() { 
    if ($scope.selectedAll) { 
     $scope.selectedAll = true; 
    } else { 
     $scope.selectedAll = false; 
    } 
    angular.forEach($scope.Items, function (item) { 
     item.Selected = $scope.selectedAll; 
    }); 

}; 

});

0

在“全选”复选框上设置ng模型,然后使用ng-checked指令选择/取消全选。

<table class="table" ng-controller="myController"> 
    <thead> 
    <tr class="info"> 
     <th>Company Name</th> 
     <th>Address</th> 
     <th> 
     <input type="button" ng-model="selectAll" class="btn btn-default" id="select-all" data-toggle="button" value="Show All" aria-pressed="false"> 
     </th> 
    </tr> 
    </thead> 
    <tbody ng-repeat="company in fieldData"> 
    <tr> 
    <td>{{ company.name }}</td> 
    <td>{{ company.address }}</td> 
    <td style="text-align: center"> 
     <input type="button" class="btn btn-default" id="select-one" data-toggle="button" value="Show" aria-pressed="false" ng-checked="selectAll"> 
    </td> 
    </tr> 
    </tbody> 
</table>