這似乎不適合我。我在tr
上有ng-repeat
,ng-click
和ng-class
。點擊tr應該切換到.error
。ng-repeat的切換錶行ng-class
目前點擊tr
將改變類中的所有錶行。
<!doctype html>
<html lang="en" ng-app="studentApp">
<head>
<meta charset="UTF-8">
<style>
.is-grey-true { background-color: #ccc; }
.error { background-color: red; }
</style>
<script type="text/javascript" src="js/angular.min.js"></script>
</head>
<body ng-controller="StudentController">
<table ng-hide="showTable">
<tr ng-repeat="student in students" ng-class="{error : isGrey}" ng-click="toggleClass()">
<td>{{student.id}}</td>
<td>{{student.firstname}}</td>
<td>{{student.lastname}}</td>
</tr>
</table>
<script type="text/javascript">
var studentApp = angular.module('studentApp',[]);
studentApp.controller('StudentController', function($scope){
var students = [
{ id:1, firstname: 'Mahesh', lastname: 'Sapkal'},
{ id:2, firstname: 'Hardik', lastname: 'Joshi'},
{ id:3, firstname: 'Sagar', lastname: 'Mhatre'}
];
$scope.isGrey = false;
$scope.toggleClass = function() {
$scope.isGrey = true;
};
});
</script>
</body>
</html>
請問你能把小提琴嗎? –
@John:加入jsfiddle。 –
http://jsfiddle.net/hGE27/繼承人工作小提琴 –