发布网友 发布时间:2022-04-20 07:49
共1个回答
热心网友 时间:2022-05-18 01:18
使用ng-model把radio绑到一个变量上,ng-value使用表达式来表示值。选中时它的值就是ng-value的值了。测试代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>radio的绑定</title>
<script src="angular.js"></script>
<style>
</style>
</head>
<body ng-app="app">
<div ng-controller="appCon">
<form ng-submit="ok()">
<div>
<input type="radio" name="a" ng-value="a" ng-model="c">11 <input type="text" ng-model="a">
<input type="radio" name="a" ng-value="b" ng-model="c">22<input type="text" ng-model="b">
</div>
<h1>{{c}}<h1>
<input type="submit" value="submit">
</form>
</div>
<script>
var app = angular.mole('app', []);
app.controller('appCon', function($scope) {
$scope.ok = function(){
console.dir($scope.c);
}
});
</script>
</body>
</html>