javascript函数,该函数不起作用,但不会显示任何错误

javascript function that is not working but does not display any mistakes

本文关键字:函数 显示 任何 错误 不起作用 javascript      更新时间:2023-09-26

我在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))都将用字符串而不是数字来完成。