gpt4 book ai didi

javascript - 如何检查 ng-repeat 生成的第一个 radio 输入?

转载 作者:行者123 更新时间:2023-12-03 12:07:59 26 4
gpt4 key购买 nike

这是我的代码:

<div ng-repeat="color in item.color">
<input id="{{color}}" name="color" type="radio" value="{{color}}" ng-model="$parent.chosenColor" />
<label for="{{color}}">{{color}}</label>
</div>

它会生成三个 radio 输入,正如它应该的那样:

<div ng-repeat="color in item.color" class="ng-scope">
<input class="ng-pristine ng-valid" id="beige" name="color" value="beige" ng-model="$parent.chosenColor" type="radio">
<label class="ng-binding" for="beige">beige</label>
</div>
<div ng-repeat="color in item.color" class="ng-scope">
<input class="ng-pristine ng-valid" id="black" name="color" value="black" ng-model="$parent.chosenColor" type="radio">
<label class="ng-binding" for="black">black</label>
</div>
<div ng-repeat="color in item.color" class="ng-scope">
<input class="ng-pristine ng-valid" id="white" name="color" value="white" ng-model="$parent.chosenColor" type="radio">
<label class="ng-binding" for="white">white</label>
</div>

我想要的是在页面加载时检查其中一个输入(最好是第一个)。我已经尝试了更多我能数出的方法,但我已经失去了理智。如何才能做到这一点?

最佳答案

在 Controller 中为模型定义适当的值:

$scope.chosenColor = $scope.item.color[0];

关于javascript - 如何检查 ng-repeat 生成的第一个 radio 输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25097867/

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