簡體   English   中英

僅在選擇單選按鈕時添加數字

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

我想僅在用戶選擇value = "serfeeadd"單選按鈕時才基於單選按鈕添加一個數字,所以我需要檢查它,將其添加到總數中,但是我不知道為什么它不起作用,但是當我刪除scope = this並且僅直接使用$scope ,它有點起作用,我只需要分配給變量的值即可。

我正在嘗試構建一個magento腕帶設計師應用程序,所有內容都僅停留在該部分上。

該代碼已被修改,以便為您提供概述,讓您知道。

 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