gpt4 book ai didi

javascript - 使用 ng-class 附加 css 时 uib-rating 没有变色

转载 作者:行者123 更新时间:2023-11-30 11:54:50 24 4
gpt4 key购买 nike

我使用 ui bootstrap 评级指令为评级使用星星,当我将鼠标悬停在这些星星上时,我需要根据它更改颜色。

HTML:

 <p class="col-xs-2">Ratings:</p>
<uib-rating ng-model="rate" max="max" read-only="isReadonly" on-hover="rating=value;hoveringOver(value)" ng-class="{{addColor}}" ng-click="viewPage||fnPutRating(rating)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating>

JS:

$scope.rate = 0;
$scope.max = 5;
$scope.isReadonly = false;
$scope.hoveringOver = function(value) {
debugger;
$scope.lol = true;
console.log(value);
switch (value) {
case 1:
$scope.addColor = "red";

break;
case 2:

$scope.addColor = "red";

break;
case 3:
$scope.addColor = "green";
break;
case 4:
$scope.addColor = "green";
break;
case 5:
$scope.addColor = "gold";
break;

}
};

CSS:

.red {
color: red;
}

.green {
color: green;
}

.gold {
color: #FFD700;
}

这是我尝试过的

DEMO

最佳答案

你需要这样写

ng-class="addColor"

代替

ng-class="{{addColor}}"

关于javascript - 使用 ng-class 附加 css 时 uib-rating 没有变色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38320826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com