简体   繁体   English

jQuery营业税

[英]jQuery Sales Tax

I have created a function (see below) that calculates a 7.5% sales tax. 我创建了一个计算7.5%营业税的函数(请参见下文)。 Now I need help doing the following: 现在,我需要执行以下操作的帮助:

  • Have totalTax() take in 2 arguments one for the price and one for the tax. 让totalTax()接受2个参数,一个作为价格,一个作为税收。

  • On submit (use the onSubmit event handler to call this function) have the function process the price and the tax by manipulating the arguments you passed in. 在提交时(使用onSubmit事件处理程序调用此函数),该函数通过处理传入的参数来处理价格和税款。

  • Have the sales tax on the page update dynamically with what ever the sales tax is that you defined for the function 7.5 percent sales tax: 使用为功能7.5%定义的销售税动态更新页面上的销售税:

    Instead of using .innerHTML use jQuery to access these document elements and write to them: 而不是使用.innerHTML,而使用jQuery来访问这些文档元素并写入它们:

      document.getElementById('requestedAmount' ).innerHTML = priceInput; document.getElementById('requestedTax' ).innerHTML = salesTax; document.getElementById('requestedTotal' ).innerHTML = totalAmount; 

Original Code: 原始代码:

<script type="text/javascript">
$().ready(function() {
    // validate the comment form when it is submitted
    $("#inputForm").validate(); 
    $("#priceInput").priceFormat({
    prefix: '',
    limit: 5,
    centsLimit: 2
}); 
});

function totalTax(){
  var priceInput = document.getElementById( 'priceInput' ).value;
  var salesTax = Math.round(((priceInput / 100) * 7.5)*100)/100;
  var totalAmount = (priceInput*1) + (salesTax * 1);

  document.getElementById( 'requestedAmount' ).innerHTML = priceInput;
  document.getElementById( 'requestedTax' ).innerHTML = salesTax;
  document.getElementById( 'requestedTotal' ).innerHTML = totalAmount;
}
</script>

<body>
<form class="cmxform" id="inputForm" method="get" action="">
  <p>
    <label for="priceInput">Enter the price: </label>
    <input id="priceInput" name="name" class="required"/>
  </p>
  <p>
    <input class="submit" type="submit" value="Submit" onclick="totalTax();"/>
  </p>
</form>
<div>Entered price:
  <p id="requestedAmount"></p>
</div>
<div>7.5 percent sales tax:
  <p id="requestedTax"></p>
</div>
<div>Total:
  <p id="requestedTotal"> </p>
</div>

for your need of converting it to jquery is here: 您需要在这里将其转换为jquery:

$(document).ready(function() {
    // validate the comment form when it is submitted
    $("#inputForm").validate(); 
    $("#priceInput").priceFormat({
    prefix: '',
    limit: 5,
    centsLimit: 2
}); 
});

function totalTax(){
  var priceInput = parseFloat(($("#priceInput").var());//document.getElementById( 'priceInput' ).value;
  var salesTax = Math.round(((priceInput / 100) * 7.5)*100)/100;
  var totalAmount = (priceInput*1) + (salesTax * 1);

  $('#requestedAmount' ).html(priceInput) ;
  $( '#requestedTax' ).html(salesTax);
  $( '#requestedTotal' ).html(totalAmount);
}
</script>

<body>
<form class="cmxform" id="inputForm" method="get" action="">
  <p>
    <label for="priceInput">Enter the price: </label>
    <input id="priceInput" name="name" class="required"/>
  </p>
  <p>
    <input class="submit" type="submit" value="Submit" onclick="totalTax();"/>
  </p>
</form>
<div>Entered price:
  <p id="requestedAmount"></p>
</div>
<div>7.5 percent sales tax:
  <p id="requestedTax"></p>
</div>
<div>Total:
  <p id="requestedTotal"> </p>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM