gpt4 book ai didi

AngularJS:ng-show/ng-hide 必填字段

转载 作者:行者123 更新时间:2023-12-04 22:59:39 24 4
gpt4 key购买 nike

我正在尝试使用 ng-show/ng-hide 显示/隐藏必填字段,除非检查输入以显示该字段。但是,表单不会提交,因为隐藏字段是必需的(除非我选择查看隐藏的附加字段的选项)。我在必填字段上使用 ng-hide 的原因是显示可能仅在需要时才需要的其他字段。有没有一种方法可以动态更改“隐藏”输入的属性?

例子:

Check Me to Show Additional Fields
<input type="checkbox" ng-model="checked">

Additional Fields
<input type="number" class="form-control" id="inputamount" data-ng-model="itemamount" step="any" required ng-show="checked"/>
<input type="text" class="form-control" id="inputlocation" data-ng-model="itemlocation" placeholder="Location" required ng-show="checked"/>

最佳答案

您可以使用 ng-required它将设置与 checked 对应的必需属性你的输入模型的boleon

<input type="number" ng-required="{{checked}}" class="form-control" id="inputamount"
data-ng-model="itemamount" step="any" ng-show="checked"/>

关于AngularJS:ng-show/ng-hide 必填字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29615275/

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