0
我想使6個按鈕是可選的。添加兩個以上時遇到問題。第三個按鈕是選擇其他按鈕,並且這些按鈕在單擊兩次時取消選擇自己。這是不希望的。一團糟。任何人都可以幫我解決這個問題嗎? 這裏是我的代碼:Onclick按鈕更改AngularUI
<div ng-app="plunker">
<div ng-controller="MainCtrl">
<button type="button" class="btn" ng-class="{'btn-primary':isUploadActive}" ng-click="toggleActive1()">Upload</button>
<button type="button" class="btn" ng-class="{'btn-primary':isDownloadActive}" ng-click="toggleActive2()">Download</button>
</div>
</div>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.button1Active = false;
$scope.button2Active = false;
$scope.button3Active = false;
$scope.button4Active = false;
$scope.button5Active = false;
$scope.button6Active = false;
$scope.toggleActive1 = function() {
if($scope.button2Active) {
$scope.button2Active = !$scope.button2Active;
}
$scope.button1Active = !$scope.button1Active;
};
$scope.toggleActive2 = function() {
if($scope.button1Active) {
$scope.button1Active = !$scope.button1Active;
}
$scope.button2Active = !$scope.button2Active;
};
$scope.toggleActive3 = function() {
if($scope.button3Active) {
$scope.button3Active = $scope.button3Active;
}
$scope.button2Active = !$scope.button2Active;
$scope.button1Active = !$scope.button1Active;
$scope.button4Active = !$scope.button4Active;
$scope.button5Active = !$scope.button5Active;
$scope.button6Active = !$scope.button6Active;
};
});
<div id="contentDiv">
<div ng-app="plunker">
<div ng-controller="MainCtrl">
<button type="button" class="btn" ng-class="{'btn-primary':button1Active}" ng-click="toggleActive1()">Upload</button>
<button type="button" class="btn" ng-class="{'btn-primary':button2Active}" ng-click="toggleActive2()">Download</button>
<button type="button" class="btn" ng-class="{'btn-primary':button3Active}" ng-click="toggleActive3()">Purchased</button>
</div>
</div>
非常感謝!我一直在試圖弄清楚這幾天。 – user3159568