我在我的圖標頁面結合的產品列表從數據庫, 最初我展示glyphicon關閉所有項目,當我點擊列表項正在改變單擊項目glyphicon就ok, 但如果我選擇在列表中第一項的任何其他項目glyphicon改變就ok,我想改變點擊項目圖標如何改變點擊項目glyphicon
我的代碼是 視圖
<div class="collapse navbar-collapse " id="myNavbar">
<ul class="nav navbar-nav">
<li ng-repeat="prod in products">
<a href="#" id="{{prod.ID}}" class="productClass" ng-click="getModules($event)">{{prod.PRODCTNAME}}<span id="iProduct" class="glyphicon glyphicon-off ChangeButtonColorOrangeRed"></span></a>
</li>
</ul>
</div>
JS
$scope.getModules = function (event) {
var prodID = event.target.id;
var productElement = angular.element(document.querySelector('#iProduct'));
productElement.toggleClass('glyphicon glyphicon-off ChangeButtonColorOrangeRed').toggleClass('glyphicon glyphicon-ok ChangeButtonColorGreen');
var moduleDiv = angular.element(document.querySelector('#divModule'));
moduleDiv.toggleClass('divProductsHide').toggleClass('divProductsShow');
productService.getModules(prodID).then(function (d) {
$scope.modules = d.data;
}, function (error) {
alert('Error!');
});
};
CSS
<style>
.ChangeButtonColorOrangeRed {
color: orangered;
}
.ChangeButtonColorGreen {
color: green;
}
看到這個http://jsfiddle.net/moncef_hbey/HB7LU/17481/ – NNR