在NG-点击更改一个div的背景颜色 [英] Changing background color of a div on ng-click
问题描述
我要改变它已经有一个backkground颜色是白色的奇数元素和灰色,即使元素的div的背景颜色。
不知道为什么它不工作的jsfiddle。
在div也有,我没有在的jsfiddle例如使用了NG-点击。
我想改变它被点击黄色的div的颜色。
这里的jsfiddle链接.... 链接
基本code -
< DIV NG-应用=对myApp>
< DIV NG控制器='Ctrl键'>
< DIV NG重复= NG式的jsonContacts项目'='{左:(?$持续lastX:空)+PX,顶:(?$持续lastY:空)+PX }'> {{}项}< / DIV>
< / DIV>
< / DIV>
使用 ngClassOdd 一>和 ngClassEven :纳克级的奇= 奇纳克级,甚至=偶
。
和添加'奇和均匀类你的CSS文件,它应该工作。
检查此upadted版本: http://jsfiddle.net/HB7LU/17468/
编辑:我添加了改变黄色背景
I want to change the background color of a div which already has a backkground color that is white for odd element and grey for even element. Dont know why its not working in Jsfiddle. The div is also having a ng-click which i have not used in JSfiddle example. I want to change the color of the div which is clicked to yellow color. Here is JsFiddle Link....LINK
Basic Code-
<div ng-app="myApp">
<div ng-controller='Ctrl'>
<div ng-repeat='item in jsonContacts' ng-style='{"left":($last?lastX:null)+"px","top":($last?lastY:null)+"px"}'>{{item}}</div>
</div>
</div>
Use ngClassOdd and ngClassEven : ng-class-odd="'odd'" ng-class-even="'even'"
.
and add 'odd' and 'even' class to your css file and it should work.
check this upadted version : http://jsfiddle.net/HB7LU/17468/
Edit : I added the change to yellow background
这篇关于在NG-点击更改一个div的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!