在NG-点击更改一个div的背景颜色 [英] Changing background color of a div on ng-click

查看:447
本文介绍了在NG-点击更改一个div的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要改变它已经有一个backkground颜色是白色的奇数元素和灰色,即使元素的div的背景颜色。
不知道为什么它不工作的jsfiddle。
在div也有,我没有在的jsfiddle例如使用了NG-点击。
我想改变它被点击黄色的div的颜色。
这里的jsfiddle链接.... 链接

基本code -

 < D​​IV NG-应用=对myApp>
    < D​​IV NG控制器='Ctrl键'>
        < D​​IV 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆