我有两个单选按钮 pass
和 fail
.
如何获取所选单选按钮的值。
<div class="col-md-4">
Result
<div class="radio">
<label><input type="radio" name="rdoResult">pass</label>
</div>
<div class="radio">
<label><input type="radio" name="rdoResult">fail</label>
</div>
</div>
我是否需要使用 ng-model 或其他东西。在 jquery 中,我很了解 angularjs 中的事情。
最佳答案
两者应该有相同的 ng-model
与不同 ng-value
(用于选择 option
s 或 radio
按钮),以便在 result
上更改所选值$scope 变量,您可以在表单提交或单击按钮时在 Controller 中获取该值。
标记
<div class="col-md-4">
Result
<div class="radio">
<label>
<input ng-model="result" type="radio" name="rdoResult" ng-value="'pass'">
pass
</label>
</div>
<div class="radio">
<label>
<input ng-model="result" type="radio" name="rdoResult" ng-value="'fail'">
fail
</label>
</div>
</div>
关于angularjs - 如何在angularjs中获取所选单选按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32450288/