gpt4 book ai didi

javascript - 乘以税收并添加到总额中

转载 作者:行者123 更新时间:2023-12-02 19:30:30 25 4
gpt4 key购买 nike

我们并不总是需要在订单中加税,因此我需要一种默认情况下绕过税费的方法,除非另有说明。

所以我有以下文本框:

  <input  class="txt1" type="text" name="subtotal" value="" id="subtotal"
size="16" tabindex="42" onChange="enableBeforeUnload();"
onKeyUp="enableBeforeUnload();">

我的这个文本框工作正常 - 它对值进行求和。

我有两个文本框,我试图将它们乘以税率并显示总计:

 <input  class="txt1" type="text" name="tax" id="tax" value="1" size="16" tabindex="42"
onChange="enableBeforeUnload();" onKeyUp="enableBeforeUnload();">

<input class="txt2" type="text" name="total1" value="" id="total1" size="16"
tabindex="42" onChange="enableBeforeUnload();" onKeyUp="enableBeforeUnload();">

我尝试使用以下命令,但没有成功:

 var tax = +$("#tax").val(),          // get tax and convert to a number
total = tax ? sum * tax : sum; // if tax is a non-zero number multiply
// otherwise just take the sum as is

还有这个:

 totAmt.val(sum + sum*parseFloat(taxAmt.val()/100));

我无法正确实现。提前致谢。

http://jsfiddle.net/thetylercox/jh2Ne/7/我无法让它正常工作 http://soldbybillcox.com/treasure/demo.php它在这里工作正常

最佳答案

对于初学者,您正在调用:

$("#tax")

但是您没有带有税号的元素。你可以使用:

$("input[name=tax]")

-编辑->那么问题是获取值,还是计算总数的逻辑?您可以将税务逻辑放入函数中:

function getTax(tax){
var taxFloat = parseFloat(tax)
if(isNaN(taxFloat)){
return 1;
}else{
return taxFloat;
}
}

然后使用:

total = getTax($('#tax').val()) * sum;

关于javascript - 乘以税收并添加到总额中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11546743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com