javascript - 更新页面加载时的价格字段

标签 javascript jquery price

我正在尝试在加载页面上激活一个函数,该函数是获取“input#quantity”中的数值并在页面加载激活函数currentPrice上计算“input.final-price”。但在页面加载时,页面加载时不会更新字段。

function currentPrice() {
  var priceProduct = parseFloat($.trim($('span.price').html().replace(",", "").replace("$", "")));	
  var convertion = ((priceProduct)/100).toFixed(2);
  var price = parseFloat($("input#quantity").val());
  var total = ((convertion) * (price)).toFixed(2);
  $("input.final-price").val(total);
  }
// Onload
$(document).on("load", "input", currentPrice);

最佳答案

您应该等到文档加载然后运行您的函数

$(function(){
    currentPrice();
});

上面是 $(document).ready() 的简写

关于javascript - 更新页面加载时的价格字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44202621/

相关文章:

php - 避免 Woocommerce 中特定产品类别的购物车商品价格更新

javascript - 如何在firebase auth中更改电子邮件?

javascript - 如何使用jquery将.current类添加到父类li

javascript - 删除尾随零到小数点后 2 位

javascript - 如何使用 jQuery 更新属性?

javascript - Xdomain ajax html scrape 在 jquery 中包装数据响应时加载图像

PHP/MySQL 定价路线

javascript - JQGrid inlineNav AddParams 使用 EditParams 中的属性

javascript - 将 Javascript 正则表达式转换为 PHP

javascript - NoUiSlider 在滑动和使用键盘时未发出正确的值