我正在尝试在加载页面上激活一个函数,该函数是获取“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/