angJs使选中的li背景颜色不同

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
<script type="text/javascript" src="../js/angular-1.2.22.js" ></script>
<script>
var myApp = angular.module("myApp", []);
myApp.controller("testCtrl", function($scope){
$scope.data = [0,1,2,3,4];
$scope.isCurrent = function(index){
$scope.bg = [];
$scope.bg[index] = 'current';
}
});
</script>
<style>
ul { margin:100px auto; width:1120px; list-style:none}
ul li { display:block; width:200px; height:200px; background:#efefef; border:solid 1px #000; float:left; margin:10px; cursor:pointer}
.current { background:#f00}
</style>
</head>

<body ng-app="myApp">
<ul ng-controller="testCtrl">
<li ng-repeat="item in data" ng-class="bg[$index]" ng-click="isCurrent($index)"></li>
</ul>
</body>
</html>

上一篇:java实现wc功能


下一篇:不用ide编译java程序时调用jar包