改变动态价格的问题

时间:2015-12-17 16:10:18

标签: javascript jquery

我有一家汽车租赁公司,提供10%的预付折扣。我已经正确地格式化了总价格,但是当有人添加"额外"它停止改变价格总额10%。

这是价格字段:

<span id="cashamount" class="additional xxlarge carrental_security_deposit" data-deposit="<?php echo $available_payments['carrental-paypal-security-deposit'];?>" data-deposit-round="<?php echo $available_payments['carrental-paypal-security-deposit-round'];?>"> - </span> <span class="additional xxlarge">ISK</span>

这是我使用的Javascript:

<script type="text/javascript">//<![CDATA[
window.onload=function(){
Number.prototype.formatMoney = function(c, d, t){
var n = this, 
    c = isNaN(c = Math.abs(c)) ? 2 : c, 
    d = d == undefined ? "." : d, 
    t = t == undefined ? "," : t, 
    s = n < 0 ? "-" : "", 
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 
    j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };

var Total = $("#cashamount");
var totalNumber = Number(Total.text().replace(/[^0-9\.]+/g,""));
Total.text((totalNumber * 1.1).formatMoney(2, '.', ','));



}//]]> 

</script>

是否存在onChange变量或监控价格字段变化并相应更改的内容?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

每次触发特定事件时都可以使用jquery来执行函数,在你的情况下,像jquery change函数应该可以做到这一点:

$('#idOfPriceField').change(function() {
    // make the desired updates here
});