gpt4 book ai didi

javascript - 无法获取 Angular 单选按钮的值

转载 作者:行者123 更新时间:2023-11-28 18:09:00 25 4
gpt4 key购买 nike

我有这些单选按钮,但我无法从提交的单选按钮中获取值(value)。我尝试了完全相同的操作:http://plnkr.co/edit/4lvJclZuh0lryF1nhmdt?p=preview

HTML:

        <body ng-controller="ExamCtrl">
<form name="myForm" ng-submit="submitForm()">
<label><input type="radio" name="test" ng-model="radioValue" value="1"/> One</label>
<label><input type="radio" name="test" ng-model="radioValue" value="2"/> Two</label>
<label><input type="radio" name="test" ng-model="radioValue" value="3"/> Three</label>
<div>currently selected: {{radioValue}}</div>
<button type="submit">Submit</button>
</form>
</body>

JS:

   $scope.submitForm = function () {
console.log('Submitting');
console.log($scope.radioValue);
};

它记录“正在提交”,然后未定义

最佳答案

当我使用点“.”时它起作用符号。不知道为什么。

HTML

<body ng-controller="ExamCtrl">
<form name="myForm">
<label><input type="radio" name="test" ng-model="radio.value" value="1"/> One</label>
<label><input type="radio" name="test" ng-model="radio.value" value="2"/> Two</label>
<label><input type="radio" name="test" ng-model="radio.alue" value="3"/> Three</label>
<div>currently selected: {{radioValue}}</div>
<button ng-click="submitAnswer(radio.value)">Submit</button>
</form>
</body>

JS

$scope.submitAnswer = function (selected) {
// $scope.answer = 'A';
console.log('submitting');
console.log(selected);
};

关于javascript - 无法获取 Angular 单选按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com