简体   繁体   English

动态价格变化的问题

[英]Issues with changing dynamic prices

I have a car rental company that offers pre-paid discount of 10%. 我有一家提供10%预付折扣的租车公司。 I have formatted the total price correctly, but when someone adds an "Extra" to it, it stops changing the price total with the 10%. 我已经正确格式化了总价格,但是当有人在其中添加“额外”时,它将停止以10%更改总价格。

This is the price field: 这是价格字段:

<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>

And this is the Javascript i use: 这是我使用的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>

It's there onChange variable or something that monitors the changes to the price field and changes accordingly ?. 它是onChange变量或用于监视价格字段的更改并相应地更改的内容。

Any help on this is greatly appreciated. 在此方面的任何帮助将不胜感激。

You can use jquery to execute a function every time a specific event is fired, in your case something like the jquery change function should do the trick: 您可以在每次触发特定事件时使用jquery执行函数,在您的情况下,可以使用类似jquery change函数的技巧:

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

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

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