首页 > > > angularjs怎么获取到单选框的值?
<!doctype html>
<html ng-app="app">
<head>
<title></title>
<script type="text/javascript" src="angular.min.js"></script>
<style type="text/css">
*{margin: 0;padding:0;}
</style>
</head>
<body ng-controller="mytest">
<div class="" ng-repeat="d in data">
<p>{{d.title}}</p>
<ul>
<li ng-repeat="f in d.options">
<label><input type="radio" />{{f.title}}</label>
</li>
</ul>
</div>
<button ng-click="submit()">提交</button>
<script>
var app = angular.module("app",[]);
app.controller("mytest",function($scope){
$scope.submit = function () {
//do something
};
$scope.data = [
{
"title" : "你最喜欢吃什么水果?",
"options" : [
{
"id" : 1,
"title" : "苹果"
},
{
"id" : 2,
"title" : "橙子"
},
{
"id" : 3,
"title" : "西瓜"
}
]
},
{
"title" : "你最喜欢玩什么游戏?",
"options" : [
{
"id" : 1,
"title" : "LOL"
},
{
"id" : 2,
"title" : "魔兽世界"
},
{
"id" : 3,
"title" : "传奇"
}
]
}
];
});
</script>
</body>
</html>怎么让选择了单选框之后,点击提交按钮打印出 单选框(radio)的值啊?$scope.data的数据都是从后台取得。这里是写死 作演示,
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4549/viewspace-3139689/ ,如需转载,请注明出处,否则将追究法律责任。