gpt4 book ai didi

javascript - Angular Js :Conditionally how to disable all button and links?

转载 作者:搜寻专家 更新时间:2023-11-01 04:56:13 24 4
gpt4 key购买 nike

我在 Controller 中有一个条件。如果条件返回 true,那么我必须禁用所有链接和 ng-clicks

我们如何做:-

Controller : $scope.disableActions = true;

在 HTML 中

<button type="button" ng-click="ignoreAndRedisplay()" ng-disabled="disableActions">OpenClick</button>

所以通过这样做我必须到处写 ng-disabled="disableActions",这将是多余的,我们如何改进 n 个按钮和链接?

最佳答案

对于这种情况,我建议您做的是,将所有按钮放在单个 fieldset 中,然后在该 fieldset 上应用 ng-disabled ,如果 ng-disabled 表达式被评估为 truedisabled >

<fieldset ng-disabled="disableActions">
<button type="button" ng-click="ignoreAndRedisplay()">OpenClick</button>
<button type="button" >Some Other button</button>
<button type="button" >One more button</button>
...
</fieldset>

Demo Here


正如您在评论中要求禁用 anchor 标签一样。基本上你不能禁用 anchor 标签。您可以尝试以下 hack 以使其正常工作。

fieldset[disabled] a { 
pointer-events: none;
}

Plunker

关于javascript - Angular Js :Conditionally how to disable all button and links?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43654970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com