新税收计算
在线计算
<script>
var s = eval("3000 * 0.03 + (12000 - 3000) * 0.1 + (25000 - 12000) * 0.2 + (35000 - 25000) * 0.25");
console.log(s);
function computeTax(pretaxAmount) {
var excess = pretaxAmount - 5000;
if (excess > 0 && excess <= 3000) {
return excess * 0.03;
} else if (excess > 3000 && excess <= 12000) {
return 90 + (excess - 3000) * 0.1; // 3000 * 0.03 + (excess - 3000) * 0.1;
} else if (excess > 12000 && excess <= 25000) {
return 990 + (excess - 12000) * 0.2; // 3000 * 0.03 + (12000 - 3000) * 0.1 + (excess - 12000) * 0.2;
} else if (excess > 25000 && excess <= 35000) {
return 3590 + (excess - 25000) * 0.25; // 3000 * 0.03 + (12000 - 3000) * 0.1 + (25000 - 12000) * 0.2 + (excess - 25000) * 0.25;
} else if (excess > 35000 && excess <= 55000) {
return 6090 + (excess - 35000) * 0.3; // 3000 * 0.03 + (12000 - 3000) * 0.1 + (25000 - 12000) * 0.2 + (35000 - 25000) * 0.25 + (excess - 35000) * 0.3;
} else if (excess > 55000 && excess <= 80000) {
return 12090 + (excess - 55000) * 0.35; // 3000 * 0.03 + (12000 - 3000) * 0.1 + (25000 - 12000) * 0.2 + (35000 - 25000) * 0.25 + (55000 - 35000) * 0.3 + (excess - 55000) * 0.35;
} else {
return 19590 + (excess - 80000) * 0.45; // 3000 * 0.03 + (12000 - 3000) * 0.1 + (25000 - 12000) * 0.2 + (35000 - 25000) * 0.25 + (55000 - 35000) * 0.3 + (80000 - 55000) * 0.35 + (excess - 80000) * 0.45;
}
}
var preTaxInput = document.querySelector(".pre-tax");
var afterTaxInput = document.querySelector(".after-tax");
var computeBtn = document.querySelector(".compute-tax");
computeBtn.onclick = function () {
if (preTaxInput.value != "") {
var pretaxAmount = preTaxInput.value;
if (pretaxAmount <= 5000) {
afterTaxInput.value = `您无需缴税`;
} else {
var tax = computeTax(pretaxAmount);
afterTaxInput.value = pretaxAmount - tax;
}
}
}
</script>
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019010713171355.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80Mzc0ODgxMg==,size_16,color_FFFFFF,t_70)