AngularJs如何调用单选按钮的值?

时间:2016-11-04 07:16:02

标签: angularjs

</div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="pwd">Glossy: </label>
        <div class="checkbox">
            <label><input type="checkbox" value="">Yes</label>
            <label><input type="checkbox" value="">No</label>
        </div><br>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-4">
                <button type="submit" class="btn btn-default">Submit</button>
            </div>
        </div>
    </form>
</div>
</div>

<script>
     //document.getElementById("date").innerHTML = new Date();
    var app = angular.module("myApp",[]);
    app.controller("verify", function ($scope){

        var verifydate = function(){
          var name = $scope.ss;
            if(ss.checked){
                z = Date.parse(Date());
                z = z + 86400000;
                var mydate1 = new Date(z);
            }
        };       


    });
</script> 

`如何在angularJS中调用单选按钮的值并将其存储在变量中。我试图在控制器中创建此功能,以便我可以在跨度中打印交货日期,但我无法做到?

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以在input\[radio\]

的文档中找到所有必要信息

每个输入应该具有相同的ng-model,但具有不同的valueng-value

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.shirts = "A magnificient t-shirt with a unicorn on it !";//used with ng-value
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <input type="radio" id="poster" name="optradio" ng-model="option" value="poster">Posters
  <input type="radio" id="coffee" name="optradio" ng-model="option" value="coffee">Coffee mugs
  <input type="radio" id="shirt" name="optradio" ng-model="option" ng-value="shirts">T-shirts

  <p>You choosed : {{option}}</p>
</div>