计算税金和总额

时间:2016-03-31 18:38:04

标签: javascript html5 function

我正在尝试创建一个表格,用于计算用户输入的两种不同的税金并显示总额

我不明白问题出在哪里以及为什么没有显示出来。 我加入了剧本。

由于

<head>

 <style>
td 
{
border: 1px solid black;
padding: 20px;
margin: 20px;

 }
</style>

<script  type="text/javascript">
function calculateGST ()
{
var v_GST = 0.05;
var v_price = parseFloat(Number(document.getElementById('inputuser').value));
var v_taxes_GST = (v_price * v_GST));

return v_taxes_GST;
}



 function calculateQST ()
 {
 var v_QST = 0.09975;
 var v_price =    parseFloat(Number(document.getElementById('inputuser').value));
  var v_taxes_QST = (v_price * v_QST));

   return v_taxes_QST;

    }

  function calculatetotal ()
   {
   var v_prix = parseFloat(Number(document.getElementById('inputuser').value));
   var v_total;

    v_total = v_price + calculateQST() + calculateGST();

     return v_total;
     }

  function showTotal()
   {
   document.getElementById('valueTotal').innerHTML = showTotal();
    }

    function showQST()
    {
    document.getElementById('valueQST').innerHTML = showQST();
    }


    function showGST()
    {
    document.getElementById('valueGST').innerHTML = calculateGST();
     }

      </script>

  </head>
  <body>

 <table style ="width:75%">
 <tr>
    <td colspan=2> Example</td>
 </tr>

 <tr>
    <td colspan=2> You sell a taxable good for $100. Taxes are calculated as    follows: </td>
    </tr>

 <tr> 
    <td> Selling price </td> 
    <td> <input type="text" id="inputuser"> </td> 
</tr>

<tr> 
    <td> GST ($100 × 5%)  </td>
    <td> <input type="button" value="calculate GST" onclick="showGST();"/>
<div id = "valueGST" class="GST"></div> </td>
</tr>

<tr> 
    <td> QST ($100 × 9.975%)  </td>
    <td> <input type="button" value="calculate QST" onclick="showQST();"/>
<div id = "valueQST" class="QST"></div> </td>
</tr>

<tr> 
    <td> Total  </td>
    <td> <input type="button" value="calculate total"   onclick="showTotal();"/>
   <div id = "valueTotal" class="total"></div> </td>
    </tr>   




   </table>



    </body>
  </html>

1 个答案:

答案 0 :(得分:2)

您的showTotal()showQST()函数正在调用自己。

function showTotal() {
  document.getElementById('valueTotal').innerHTML = calculatetotal();
}

function showQST() {
  document.getElementById('valueQST').innerHTML = calculateQST();
}

function showGST() {
  document.getElementById('valueGST').innerHTML = calculateGST();
}