javascript - 单击一次按钮禁用多个按钮

标签 javascript html angularjs

我正在使用 angularjs 中的 ng-repeat 获取表中的数据。该表包含我需要接受或拒绝的 id。我想在按下其中一个按钮时禁用一行中的其他按钮。我可以使用 ng-disabled 来完成此操作,但所有行的按钮都被禁用。有人可以帮忙吗..谢谢

这是我的代码

<tr ng-repeat="result in results "  >

<td>{{$index +1}}</td>
 <td>{{result.companyName}}</td>
<td>{{result.id}}</td>
<td>{{result.createdAt}}</td>
<td>{{result.modifiedAt}}</td              
 <td>{{result.Status}}</td>
 <td>
      <button class="btn"      ng-click="processStart(result.id)"> Approve </button>
    </td>
  <td>
        <button class="btn" ng-click="processReject(result.id)"         ng-disabled="showRejectButton" >
   <span class="glyphicon glyphicon-remove"></span>  Reject          </button>

最佳答案

问题是您将每个拒绝按钮绑定(bind)到 ng-disabled 条件的同一变量,即 ng-disabled="showRejectButton"

您需要将每个按钮绑定(bind)到它们自己的变量。您可以通过将 $scope.showRejectButton 设为数组(然后在表中使用 ng-disabled="showRejectButton[$index]")或附加 showRejectButton 来完成此操作到每个结果对象(然后在表中使用 ng-disabled="result.showRejectButton")。

关于javascript - 单击一次按钮禁用多个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32965397/

相关文章:

javascript - Ionic 2 - (任何窗口).resolveLocalFileSystemURL() 抛出错误

c# - 带有 HTML5 控件的 Visual Studios Formview

javascript - JQuery 绑定(bind)在同一元素上,独特的行为

javascript - 在没有 url 帮助的情况下在 Controller 之间传递数据?

javascript - 从 View 中存在的 google api 调用 Angular Controller 中的函数

javascript - 混洗嵌套数组的不同部分

javascript - 更改函数内的 var,但不使用它

javascript - 为什么 OnClick 不改回颜色?

angularjs - Chrome 打包应用程序 AngularJS 样板模板

javascript - 如何判断哪个按钮调用了函数?