</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中调用单选按钮的值并将其存储在变量中。我试图在控制器中创建此功能,以便我可以在跨度中打印交货日期,但我无法做到?
答案 0 :(得分:1)
您可以在input\[radio\]
每个输入应该具有相同的ng-model
,但具有不同的value
或ng-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>