gpt4 book ai didi

javascript - 单击 angularjs 时切换单选按钮

转载 作者:行者123 更新时间:2023-12-02 16:27:58 24 4
gpt4 key购买 nike

如何切换单选按钮,例如单击每个单选按钮应启用相应的元素(例如元素),反之亦然。我尝试过的代码:

复选框 1:<input type="radio" name="somethign" value="1" ng-model="checkboxSelection" ng-click="disable1='true';disable2='false'"/>

<select ng-model="something" ng-options="r.id as r.name for r in data1" ng-disabled="disable1">

复选框 2:<input type="radio" name="somethign" value="2" ng-model="checkboxSelection" ng-click="disable2='true';disable1='false';"/>

<select ng-model="something" ng-options="r.id as r.name for r in data2" ng-disabled="disable2">

我不会根据上面的代码进行切换。任何人都可以建议不同的替代方案吗?谢谢

最佳答案

更简洁的实现是根据所选值禁用选择项:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-init="checkboxSelection = 1">
<input type="radio" name="somethign" value="1" ng-model="checkboxSelection"/>First
<input type="radio" name="somethign" value="2" ng-model="checkboxSelection"/>Second
<br />
<select ng-model="something1" ng-disabled="checkboxSelection != 1">
<option>A</option>
<option>B</option>
</select>
<select ng-model="something2" ng-disabled="checkboxSelection != 2">
<option>A</option>
<option>B</option>
</select>
</div>

关于javascript - 单击 angularjs 时切换单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28539062/

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