0

下面是 ng-click 的代码, 我只想要一次 click 事件,然后禁用 button。但是,如何仅将 ng-disabled 用于按钮标签(不使用输入标签)?

对于 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>
4

2 回答 2

2

你有没有尝试过:

<button ng-click="!count && myFunc()" ng-disabled="count > 0">OK</button>
于 2017-05-09T10:37:12.443 回答
1
<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>
于 2017-05-09T13:01:05.213 回答