检查选择了哪个单选按钮

时间:2016-07-07 11:31:00

标签: html angularjs

我需要选中女巫单选按钮。

styleURL

如果单选按钮被选中,我如何检查angularjs? 我也试过了,但是我没办法。

<div class="cClearFloat cInputSpace cRadioAdmin">
    <label class="cLabelJa"><input type="radio" value="Ja" name="Admin" ng-model="radioJa">Ja</label>
    <label><input type="radio" name="Admin" value="Nein" ng-model="radioNein">Nein</label>
</div>

请帮帮我。

1 个答案:

答案 0 :(得分:1)

<label class="cLabelJa"><input type="radio" value="Ja" name="Admin" ng-model="radioJa">Ja</label>
<label><input type="radio" name="Admin" value="Nein" ng-model="radioNein">Nein</label>

在这种情况下,您具有相同的名称,但它有两个不同的ng-model名称。它应该是相同的..

如果你没有选择它们,那么单选按钮的值都将是“未定义”...

要检查是否已选中,您可以使用以下

if ( !$scope.radioJa ){
     alert('comes here if the radio button is not selected');        
}
if ( $scope.radioJa ){
     alert('comes here if the radio button is selected'); 
     alert("and the value of $scope.radioJa will be `Ja` if the 1st radio button is selected");        
}