简体   繁体   English

仅在选择单选按钮时添加数字

[英]Add a number only when a radio button is selected

I want to add a number to total amount based on radio button select only if user selects radio button with value = "serfeeadd" so I need to check it, get it and add it to the total but I can't figure out why its not working but when I remove scope = this and only use $scope directly it kinda works, I just need the value assigned to the variable. 我想仅在用户选择value = "serfeeadd"单选按钮时才基于单选按钮添加一个数字,所以我需要检查它,将其添加到总数中,但是我不知道为什么它不起作用,但是当我删除scope = this并且仅直接使用$scope ,它有点起作用,我只需要分配给变量的值即可。

I am trying to build a magento wristband designer app everything is built only stuck with this part . 我正在尝试构建一个magento腕带设计师应用程序,所有内容都仅停留在该部分上。

The code has been modified to provide you guys with an overview for anything more you can let me know. 该代码已被修改,以便为您提供概述,让您知道。

 var app = angular.module('wdWristbandDesigner', []); app.controller("fontCtrl", MainController); function MainController($scope){ //scope var scope = this; scope.foo = function(){ if (scope.serialisationFeeCheck == 'serfeeadd') { scope.serialisationFee = 10; console.log(scope.serialisationFeeCheck); } else { scope.serialisationFee = 0; }; } }; 
 <section class="wd-section" ng-controller="fontCtrl as fs"> <input type="radio" name="serialno" data-ng-model="serialisationFeeCheck" value="no" >No <br> <input type="radio" name="serialno" data-ng-model="serialisationFeeCheck" value="our">Yes(Our Choice) <br> <input type="radio" id="chk" name="serialno" data-ng-model="serialisationFeeCheck" value="serfeeadd" >Yes(Your Choice) <button typ="button" ng-click="foo()" >click</button> </section> 

ng-click应该是fs.foo(),所有ng-models都需要将fs对象应用于它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM