预先警告,我是JavaScript的新手,但我能理解计算时,他们已经写好了,这是我自己写的问题。我正试图为我们的网站创建一个在线税务计算器。我已经找到了一个工作的基础,但我需要更新它,以便计算是正确的。
的目标:
用户输入他们的总收入并点击一个按钮“计算”。结果应该显示应付款、医疗保险税以及最后的净收入。净额=毛税-医疗保险。
我在这里的:
我找到了一些代码,提供给我一些税收计算,并将其更新为正确的值。然而,目前适用于所有税收等级的医疗保险价值(1.5%)是不正确的,实际上也有3个不同的级别。
我不知道如何将这两种计算合并在一起,然后从总收入中扣除这些来给出净结果?我没有添加任何东西来做最后的计算,在这个阶段,我正在尝试如何在一个脚本中执行多个函数。
当我一次做一次计算的时候,我试着逐渐地把它建立起来,但我一试就陷入了困境。我在http://www.faa.net.au/test/创建了一个测试页面。
我真的很想在这方面提供任何帮助。我正在等待一本JavaScript指南,以便真正抽出一些时间,正确地学习JavaScript。
我想补充的额外医疗保险计算如下:
// Calculation below needs to replace Medicare above
if (income>0 && income<=19404) {
medicare = (income*0)/100;
}
else if (income>19404 && income<=22828) {
medicare = (income*10)/100;
}
else if (income>22828) {
medicare = (income*1.5)/100;
}发布于 2012-11-28 02:26:53
您需要的javascript代码与此类似,我相信:
// I am using a javascript library called jQuery.
$(function(){
// On clicking the Calculate button
$('#calculate').on('click', function(){
// Get the value of user supplied income from the textbox
var income = parseInt($('#preIncome').val().trim()),
postIncome = 0,
medicare = 0;
console.log(income);
if(income > 0){
// Calculation below needs to replace Medicare above
if (income>0 && income<=19404) {
medicare = (income*0)/100;
}
else if (income>19404 && income<=22828) {
medicare = (income*10)/100;
}
else if (income>22828) {
medicare = (income*1.5)/100;
}
// Calculate the new income based on derived medicare value
postIncome = income - medicare;
}
// Set the new medicare and income values to the textboxes
$('#postIncome').val(postIncome);
$('#medicare').val(medicare);
});
});这里有一个工作演示:http://jsfiddle.net/pratik136/YdWNA/
发布于 2012-11-28 02:33:40
这是你身体的内脏:
<form name="calc">
Gross Income: <input type="text" class="innerc resform" size="15" name="income">
<input type="button" onclick="calculate(this)" name="result" value="Calculate"
class="calcButton">
Income Tax: <input type="text" size="15" class="resform" name="tax">
Medicare Levy: <input type="text" size="15" class="resform" name="medicare">
Net Income: <input type="text" size="15" class="resform" name="net">
</form>如果从“计算”按钮传递this (请注意已更改的侦听器和值的添加),用于计算医疗保险税的函数可以是:
function calculate(element) {
var form = element.form;
var income = form.income.value;
// 0 for income less than threshold
var medicare = 0;
// Add 1% of income between 19404 and 22828
if (income > 19404 && income <= 22828) {
medicare = (income - 19404) * 0.01;
}
// Add 1.5% of income over 22828
if (income > 22828) {
medicare += (income - 22828) * 0.015;
}
}希望这能让你走。
https://stackoverflow.com/questions/13596619
复制相似问题