在 ng-click 上更改 div 的背景颜色 [英] Changing background color of a div on ng-click
问题描述
我想更改一个 div 的背景颜色,该 div 已经有一个背景颜色,奇数元素为白色,偶数元素为灰色.不知道为什么它在 Jsfiddle 中不起作用.div 也有一个 ng-click,我在 JSfiddle 示例中没有使用过.我想将单击的 div 的颜色更改为黄色.这是 JsFiddle 链接....LINK
基本代码-
<div ng-controller='Ctrl'><div ng-repeat='item in jsonContacts' ng-style='{"left":($last?lastX:null)+"px","top":($last?lastY:null)+"px"}'>{{item}}</div>
使用 ngClassOdd 和 ngClassEven : ng-class-odd="'odd'" ng-class-even="'even'"
.
并将odd"和even"类添加到您的 css 文件中,它应该可以工作.
检查这个更新版本: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-click 上更改 div 的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!