【发布时间】:2016-02-10 12:15:52
【问题描述】:
我在 AngularJS 中有一个简单的工资计算表。 以下是我的html:
<div ng-app="myApp" ng-controller="personCtrl">
Gross: <input type= "text" ng-model="Gross"><br>
<br/>
Deductions:<fieldset>
IT : <input type= "text" size = 12 maxlength = 4 ng-model="IT"><br>
CPP : <input type= "text" ng-model="CPP"><br>
EI : <input type= "text" ng-model="EI"><br>
<br>
</fieldset>
Gender:<fieldset>
<input type="radio" ng-model = "sex" value = "male"> Male
<br>
<input type="radio" ng-model ="sex" value = "female" > Female
</fieldset>
Dependants:<fieldset>
<select>
<option value="3">3</option>
<option value="4">4</option>
</select>
</fieldset>
<br/>
{{Salary()}}
</div>
-- JavaScript 代码如下:
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.Gross= 0;
$scope.IT = 0;
$scope.CPP = 0;
$scope.EI = 0;
$scope.sex =
$scope.Salary = function() {
return ( Number($scope.Gross) - ( Number($scope.Gross) * (Number($scope.IT)/100 ) + Number($scope.Gross) * (Number($scope.CPP)/100 ) + Number($scope.Gross) * (Number($scope.EI)/100 )) );
}
});
我的问题是我可以使用输入框计算扣除额,但是当 我选择性别女性,然后 I.Tex 应该减少 2%。 同样,如果我在受抚养人中选择 3,那么 ITex 也应该扣除 1%。 实际上我无法在计算中实现单选按钮和列表
【问题讨论】: