angular.js - angular ng-repeat改變某個(gè)的背景顏色
問(wèn)題描述
如圖所示,上面的5個(gè)塊,用ng-repeat循環(huán)輸出,怎樣實(shí)現(xiàn)當(dāng)點(diǎn)擊某一塊(如塊2)時(shí),該塊的背景顏色變?yōu)榧t色?其他的塊的顏色不變。謝謝指點(diǎn)。
問(wèn)題解答
回答1:方法太多,ng-click,ng-class,directive實(shí)現(xiàn)都可以啊這是直接寫的方法,僅供參考html:
<p> <span ng- ng-repeat='s in list' ng-bind='s' ng-click='changeStatus(s)'></span></p>
js
$scope.list = [1,2,3,4,5];$scope.changeStatus = function(index){ $scope.selected = index;}回答2:
添加點(diǎn)擊事件。把當(dāng)前循環(huán)的$index和$event傳過(guò)去。然后自己通過(guò)angular jq來(lái)就處理就OK啊。
回答3:給你個(gè)現(xiàn)成的代碼:HTML
<p class=’options’> <span class=’option’ ng- ng-repeat='s in orderStatus' ng-bind='s.l' ng-click='clickStatus(s)'></span></p>
JS
$scope.clickStatus = function(prop) { prop._selected = !prop._selected;};
CSS
.option{display:inline-block;border:1px solid green;padding:.25em;margin:.5em .5em 0 0;}.option.selected{background:green;color:white;}
我正打算寫個(gè)directive做這個(gè)
回答4:http://runjs.cn/detail/yfnwk6ho
相關(guān)文章:
1. javascript - sublime快鍵鍵問(wèn)題2. javascript - immutable配合react提升性能?3. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化4. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語(yǔ)法錯(cuò)誤5. css - 寫頁(yè)面遇到個(gè)布局問(wèn)題,求大佬們幫解答,在線等,急!~6. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問(wèn)7. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?8. phpstudy8.1支持win11系統(tǒng)嗎?9. 實(shí)現(xiàn)bing搜索工具urlAPI提交10. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問(wèn)?

網(wǎng)公網(wǎng)安備