Angularjs 如何检查单选按钮?
如何检查单选按钮? 如果Angularjs 如何检查单选按钮?,angularjs,Angularjs,如何检查单选按钮? 如果$type=='1'检查输入并设置值=1 我试过: 第一次输入: <input type="radio" name="sex[]" ng-init="formData.sex = '<?=($type == '1' ? '1' : null)?>" ng-model="formData.sex"' required> <input type="radio"
$type=='1'
检查输入并设置值=1
我试过:
第一次输入:
<input type="radio"
name="sex[]"
ng-init="formData.sex = '<?=($type == '1' ? '1' : null)?>"
ng-model="formData.sex"'
required>
<input type="radio"
name="sex[]"
ng-init="formData.sex = '<?=($type == '2' ? '2' : null)?>"
ng-model="formData.sex"'
required>
”
ng model=“formData.sex”
必需>
当我提交表单时,我看到
formData.sex=true
,因此Angular JS从第二个输入中获取值,因为条件$type=='1'
为true。您仍然需要一个值:
<input type="radio"
name="sex"
value="1"
ng-init="formData.sex = '<?=($type == '1' ? '1' : null)?>"
ng-model="formData.sex"'
required>
<input type="radio"
name="sex"
value="2"
ng-init="formData.sex = '<?=($type == '2' ? '2' : null)?>"
ng-model="formData.sex"'
required>
”
ng model=“formData.sex”
必需>
试着用Plunker看看这一点
如果类型为1,则选中第一个单选按钮;如果类型为2,则选中单选按钮2
这就是你要找的吗
<body ng-app="radioExample">
<script>
angular.module('radioExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.type = '2';
}]);
</script>
<form name="myForm" ng-controller="ExampleController">
<input type="radio"
name="sex"
value = '1'
ng-init="{{sex = type == '1' ? '1' : '2'}}"
ng-model="sex"
required> <label>1</label>
<input type="radio"
name="sex"
value = '2'
ng-init="{{sex = type == '2' ? '2' : '1'}}"
ng-model="sex"
required> <label>2</label>
<br/><br/> Sex is now {{sex}}
</form>
</body>
angular.module('radioExample',[])
.controller('ExampleController',['$scope',function$scope){
$scope.type='2';
}]);
1.
2.
性现在是{{Sex}
是的,我尝试了,更新了问题,问题是页面上有两个单选按钮,Angular JS从第二个按钮获取值。请参阅问题,了解通过Angular JS提交的值是多少?试过了,帮不了我