ITPub博客

首页 > > > angularjs怎么获取到单选框的值?

angularjs怎么获取到单选框的值?

作者:limiao 时间:2019-08-30 11:55:33 0 删除 编辑
<!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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Javascript 函数
请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    190
  • 访问量
    1371