如何取消选择所有无线电输入

How to Deselect All Radio Inputs?

本文关键字:无线电 输入 选择 何取消 取消      更新时间:2023-09-26

我使用的是angular,并且有一个像这样的无线电输入(如果重要的话,以某种形式):

<input type="radio"
       name="inputName"
       id="someId"
       data-ng-value=true <!-- This select "true" for my ng-model when clicked-->
       ng-model = "nameOfMyVarIn$scope"
       ng-change = "thisRunsWhenSelectionIsmade(true)"
       required></input>

我想清除此输入。清除绑定到ng模型的变量会清除该变量,但不会清除复选框。我找不到如何在文档或随机文章中清除单选按钮本身——它保持选中状态。我从文档中快速复制了这个例子,并添加了$scope.clearSelection——目标是让这个函数取消选择所选的输入。在实际应用程序中,我在表单中有其他输入,所以我不能只清除整个表单

Plnkr

使用您的Plnkr,我将color设置为null,它清除了该值。这是你想要的吗?

$scope.clearSelection = function(){
    $scope.color = null;
}

这是更新的Plnkr