2017-05-09 40 views
0

以下是ng-click的代碼,我只想點擊一次事件,然後禁用按鈕。但是,如何將ng-disabled僅用於按鈕標籤(不使用輸入標籤)?使用ng-disable單擊一次後禁用按鈕

對於初學者來說,angularjs的建議是非常值得讚賞的。

<html> 
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> 
</script> 
<body ng-app="myApp"> 
<div ng-controller="myCtrl"> 
<p>Click the button to run a function:</p> 
<button ng-click="!count && myFunc()">OK</button> 
<p>The button has been clicked {{count}} times.</p> 
</div> 
<script> 
angular.module('myApp', []) 
.controller('myCtrl', ['$scope', function($scope) { 
$scope.count = 0; 
$scope.myFunc = function() { 
$scope.count++; 
}; 
    }]); 
    </script> 
    </body> 
    </html> 

回答

1

你試過:

因爲這個點擊的
<button ng-click="!count && myFunc()" ng-disabled="count > 0">OK</button> 
+0

是的,僅限於一次。 –

0
<script> 
angular.module('myApp', []) 
.controller('myCtrl', ['$scope', function($scope) { 
$scope.count = 0; 
$scope.myFunc = function() { 
$scope.count++; 
    if($scope.count > 1){ 
     angular.element('button').addClass('disableButton'); 
    } 
}; 
    }]); 
    </script> 

<style> 
.disableButton{ 
Change color of button to #848d95 
} 
</style>