javascript函数,该函数不起作用,但不会显示任何错误
javascript function that is not working but does not display any mistakes
我在roder中用javascript做了一个函数来计算辩护内阁的费用。
他们要求我这样做,事实上这与文件的数量成正比。并且是递减的。
金额越多,百分比就会越小,但对于每个人来说。
事实上,当我没有首付款时,它会计算罚款。当我注册付款时,它不会显示任何内容,而且我在控制台中没有错误。
这是我做的函数。
<script type="text/javascript">
function hono(p1,p2,p3,p4,t1,t2,t3,type,versement,montantacompte)
{
var p1 = 5000.00;
var p2 = 5000.01;
var p3 = 8000.00;
var p4 = 8000.01;
var t1 = 17.00;
var t2 = 10.00;
var t3 = 6.00;
var type = "d";
var versement = 150.00;
var montantacompte = document.getElementById("montantacompte").value;
if (type== "d")
{
if(versement== 0.00 && montantacompte <= p1)
{
reste1= montantacompte;
pc= t1/100;
taux1= pc+1;
h1=((reste1*taux1)-reste1);
honoraires=h1;
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if(versement < p1 && (versement + montantacompte) <= p1)
{
reste1= montantacompte;
pc= t1/100;
taux1= pc+1;
h1= (reste1*taux1)-reste1;
honoraires= h1;
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if(versement <= p1 && (versement+montantacompte)>= p2 && (versement+montantacompte)<=p3)
{
reste1=p1-versement;
pc=t1/100;
taux1=pc+1;
h1=(reste1*taux1)-reste1;
reste2=montantacompte-reste1;
pc2=t2/100;
taux2=pc2+1;
h2=(reste2*taux2)-reste2;
honoraires=h1+h2;
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('taux-2').value=t2;
document.getElementById('palier2').value=Math.round(h2*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if (versement==0.00 && montantacompte>=p2 && montantacompte <=p3)
{
reste2=montantacompte-p1;
reste1=p1;
pc=(t1/100);
taux1=pc+1;
h1=((reste1*taux1)-reste1);
pc2=(t2/100);
taux2=pc2+1;
h2=((reste2*taux2)-reste2);
honoraires=(h1+h2);
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('taux-2').value=t2;
document.getElementById('palier2').value=Math.round(h2*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if(versement<=p3 && versement>=p2 && (versement+montantacompte)>=p2 && (versement+montantacompte)<=p3)
{
reste1=montantacompte;
pc=(t2/100);
taux1=pc+1;
h1=((reste1*taux1)-reste1);
honoraires=h1;
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if(versement>=p2 && versement<=p3 && (versement+montantacompte)>=p4)
{
reste1=p4-versement;
pc=(t2/100);
taux2=pc+1;
h2=((reste1*taux2)-reste1);
reste2=montantacompte-reste1;
pc2=(t3/100);
taux3=pc2+1;
h3=((reste2*taux3)-reste2);
honoraires=(h2+h3);
document.getElementById('taux-3').value=t3;
document.getElementById('palier3').value=Math.round(h3*100)/100;
document.getElementById('taux-2').value=t2;
document.getElementById('palier2').value=Math.round(h2*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if(versement==0.00 && montantacompte>=p4)
{
reste1=p1;
reste2=p3-p2;
pc=(t1/100);
taux1=pc+1;
h1=((reste1*taux1)-reste1);
pc2=(t2/100);
taux2=pc2+1;
h2=((reste2*taux2)-reste2);
reste3=(montantacompte-reste1-reste2);
pc3=(t3/100);
taux3=pc3+1;
h3=((reste3*taux3)-reste3);
honoraires=(h1+h2+h3);
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('taux-2').value=t2;
document.getElementById('palier2').value=Math.round(h2*100)/100;
document.getElementById('taux-3').value=t3;
document.getElementById('palier3').value=Math.round(h3*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
else if(versement>=p4)
{
reste3=montantacompte;
pc3=(t3/100);
taux3=pc3+1;
h3=((reste3*taux3)-reste3);
honoraires=(h3);
document.getElementById('taux-3').value=t3;
document.getElementById('palier3').value=Math.round(h3*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
}
if (type=="l")
{
pc1=(t1/100);
taux1=pc1+1;
honoraires=montantacompte*taux1;
document.getElementById('taux-1').value=t1;
document.getElementById('palier1').value=Math.round(h1*100)/100;
document.getElementById('sommehonoraires').value=Math.round(honoraires*100)/100;
}
</script>
此外,所有函数都使用if(versement== 0.00 && montantacompte <= p1)
及其后的情况,依此类推,直到else if(versement < p1 && (versement + montantacompte) <= p1)
结束。
我不明白为什么它不起作用。
尝试通过替换来"修复"它
var montantacompte = document.getElementById("montantacompte").value;
通过
var montantacompte = parseFloat(document.getElementById("montantacompte").value);
类型似乎很混乱——当你得到字段值时,它是字符串,所以任何其他操作(如(verement+montantaconte))都将用字符串而不是数字来完成。
相关文章:
- 更新URL时使用Javascript函数显示日期
- 使用 js 函数显示 HTML 表单的结果
- Javascript日期函数显示错误的日期
- I'm试图使用onclick函数显示函数的结果.(javascript)
- 如何使用 JavaScript 函数显示表单 asp.net
- 通过脚本在中隐藏元素,然后使用函数显示
- 向对象原型添加函数会导致函数显示在所有“OBJ 中的 X”循环中
- 图像 onclick() 函数显示带有表单详细信息的 dailog 窗口
- Javascript 日期未显示为相等,尽管 getTime() 函数显示日期相等
- Javascript函数显示用户输入数组
- PHP中用于显示模态的Echo Javascript函数显示不正确
- 使用构造函数显示模块模式
- JQuery函数显示依赖于隐藏HTML输入元素值的元素
- 为什么这个javascript使用getTime函数显示负数
- fancybox iframe内容未通过jquery函数显示
- HTML函数显示为纯文本
- 使用JavaScript函数显示日历
- Titanium,Js函数显示XML文本字段文本
- 使用JavaScript函数显示flash
- replaceWith函数显示了奇怪的结果