<ul ng-repeat="item in city" repeat-done="cityFinish()">
<li class="city city{{$index}}">{{item}}</li>
</ul>
$scope.cityFinish = function() {
$('.city').css('background', 'red');
$('.city1').css('background', 'green');
};
其中 $('.city').css('background', 'red');
有效,但是$('.city1').css('background', 'green');
無效,這是什么原因?
我項(xiàng)目嘗試是可以的 , city{{$index}}是從city0可以 你可以審查元素看下class是否變?yōu)閏ity1 ,然后可以試著斷點(diǎn)$('.city1')是否取到了dom元素
你先審查一下元素。確保它的 class 是對的。
首先,不知道你的 repeat-done
是如何寫的。這應(yīng)該不是 angularjs 自帶的。
其次,為什么不把顏色寫到 css 中,然后用 ng-class
或者 ng-style
處理,一定要用 jQuery 呢。
你的需求是不是,除了 index 為 1 的背景色為綠色,其他的都為紅色?
<ul ng-repeat="(index, item) in city">
<li class="bg-red" ng-class="{'bg-green': $index == 1}">{{item}}</li>
</ul>
.bg-red {
background: 'red';
}
.bg-green {
background: 'green';
}
能不用 jQuery 就別用,更何況你還有內(nèi)置的 jqLite 可以用。。。jQuery 作為第三方庫,如果你不針對 angularjs 封裝,那么你不能保證它的執(zhí)行一定是在生成節(jié)點(diǎn)之后的,特別是對于 custom directive。
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號