gpt4 book ai didi

javascript - 根据选中的单选按钮更改选择框

转载 作者:行者123 更新时间:2023-12-03 10:36:12 28 4
gpt4 key购买 nike

我想更改基于单选按钮的选择框的内容

我正在使用AngularJS。所以,我的选择框如下所示:

<select ng-controller="MyController">
<option ng-repeat="o in array_of_values" value="{{o.id}}">{{o.value}}</option>
</select>

现在,根据我的单选按钮是否被选中,我想要在选择框中加载一组不同的值。

我对 Angular 没有太多经验,但我怀疑我可以动态更改 $scope.array_of_valuesMyController 。类似this example的东西(官方文档)

我见过another example ,您可以在其中基于单选按钮更改 div 的内容,只需使用 ng-model + ng-show

已编辑:但我还有另一个困难:我确实有几对单选按钮/选择框,作为表格的行,并且它们是动态生成的。我可以使用纯 jQuery 加上 JavaScript 函数来获取每个单选按钮的 id,然后根据 onClick 更改特定的选择框。单选按钮的事件。但我倾向于认为有一种更优雅的方法可以做到这一点,即使用 AngularJS。我说得对吗?

有任何线索吗?我应该遵循什么方法?

提前非常感谢

最佳答案

您应该首先阅读文档并选择正确的组件。

选择 Angular 方式:https://docs.angularjs.org/api/ng/directive/ngOptions

电台:https://docs.angularjs.org/api/ng/input/input%5Bradio%5D

$观察 radio 模型并更改 array_of_values 值。更喜欢使用对象而不是值({id:0, value:"value0"})。

$scope.radio = {name:"Radio1"};
$scope.$watch('radio', function(newVal, lastVal){
if(newVal.name === 'radio2')
$scope.array_of_values = values2
};
});

关于javascript - 根据选中的单选按钮更改选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28971451/

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