我有一家汽车租赁公司,提供 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 变量或监视价格字段变化并相应变化的变量?
非常感谢对此的任何帮助。
最佳答案
您可以使用 jquery 在每次触发特定事件时执行一个函数,在您的情况下,像 jquery change
函数这样的函数应该可以解决问题:
$('#idOfPriceField').change(function() {
// make the desired updates here
});
关于javascript - 动态价格变化的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34339200/