单击角度js后禁用链接

时间:2017-01-16 22:04:30

标签: angularjs disable-link

有人可以帮我解决问题。 我需要在点击后禁用链接(立即付款)以避免多次点击。

<div class="Class1" data-ng-show="ShowButton == 'TRUE'">
<a href="javascript:void(0);" data-ng-click="PayNow()" class="btn-register">PAY NOW</a></div>

4 个答案:

答案 0 :(得分:2)

hyperlinks没有禁用属性。如果您不想做某些事情,则需要在<a>标记中添加一些样式并将标记处理到控制器中。

试试这个:

&#13;
&#13;
angular.module('myApp', [])
  .controller('myCtrl', ['$scope', function($scope) {
    $scope.isDisabled = false;
    if($scope.isDisabled === false) {
      $scope.PayNow = function() {
        $scope.isDisabled = true;
      }
    }
  }]);
&#13;
.disabled {
  cursor: not-allowed;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
    <a href="javascript:void(0)" ng-click="PayNow()" ng-class="{disabled: isDisabled}">PAY NOW</a>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

你可以在PayNow()函数中创建一个额外的变量来禁用按钮,如下所示:

JS:

$scope.PayNow = function() {
    $scope.DisabledButton = true;
    // other code 
}

<强> HTML

<a href="javascript:void(0);" data-ng-click="PayNow()" class="btn-register" ng-disabled="DisabledButton">PAY NOW</a>

答案 2 :(得分:0)

在您的HTML中

      .disabled {
          cursor: not-allowed;
        }

        <a ng-click="PayNow()" ng-class="{'disabled': DisabledButton}">Add</a>
OR

<button ng-click="PayNow()" ng-disabled="DisabledButton">Add</button>

在JS中

$scope.DisabledButton = false;
$scope.PayNow = function() {
    $scope.DisabledButton = true;
    // other code 
    ...
    //when you want to re-enable
   $scope.DisabledButton = false;
}

答案 3 :(得分:0)

我希望这能对您有帮助!!!因此,在我的示例中,我使用条件来检查数组的长度并限制按钮以创建更多文本框。另外,您可以改用count。

$scope.technologies = [];
    $scope.addtech = function () {
        $scope.minus = true;
        if ($scope.technologies.length < 3)
            $scope.technologies.push({});
    }