gpt4 book ai didi

javascript - 有没有更优雅的方法将复选框变成单选按钮?

转载 作者:行者123 更新时间:2023-11-30 11:36:19 25 4
gpt4 key购买 nike

试图将我的复选框变成单选按钮。这很好用

ng-change="second=false;third = false;fourth = false;"

这是个骗子

http://plnkr.co/edit/yTJUZcFoLsSEBjruRuEY?p=preview

除了 ng-model 之外,有没有办法让数组中的每个元素都为 false?

示例

ng-model=myArray[3]

所以 myArray[0], myArray[1], myArray[... n] 都是 falseEXCEPT myArray[3],这是真的。

最佳答案

这应该相当优雅:PLNKR

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
$scope.radio = new Array(4).fill(false)
$scope.changed = function(el){
$scope.radio = $scope.radio.map((v,i)=>i==el)
}
});

和 html:

<div>{{radio[0]}}|{{radio[1]}}|{{radio[2]}}|{{radio[3]}}
<br/>
<input ng-repeat="r in radio track by $index" type="checkbox" ng-model="radio[$index]" ng-change="changed($index)" />

关于javascript - 有没有更优雅的方法将复选框变成单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44278629/

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