码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-05-13 12:49:39      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:

<!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>

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

标签:

原文地址:http://www.cnblogs.com/zml-java/p/5487153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!