以下是代码:
我想通过angularjs点击功能来检查单选按钮值吗?
<input type="radio" name="calender" value="calender">
<input type="radio" name="calender" value="calender2" checked="checked">
<button ng-click="get_val($event)">Click</button>
$scope.get_val= function(event)
{
}
答案 0 :(得分:2)
您可以在此添加此值以获取值
var flag_item_val = $("input:radio[name=calender]:checked").val();
答案 1 :(得分:1)
请查看下面的代码段,了解如何将值绑定到ng-model
,您可以在范围内的任何位置访问它们。
var app = angular.module('plunker', []);
app.controller('MainCtrl',
function MainCtrl($scope) {
$scope.radioVal = 'calender2';
$scope.get_val = function(event) {
console.log($scope.radioVal);
}
});
&#13;
<script data-require="angularjs@1.5.8" data-semver="1.5.8" src="https://opensource.keycdn.com/angularjs/1.5.8/angular.min.js"></script>
<div ng-app="plunker" ng-controller="MainCtrl">
<input type="radio" name="calender" value="calender" ng-model="radioVal">
<input type="radio" name="calender" value="calender2" ng-model="radioVal">
<button ng-click="get_val($event)">Click</button>
</div>
&#13;