如何整合这两个简单的 javascript 代码?
How can I integrate these two simple javascript codes?
我已经设置了一个 javascript 代码来给出总数。我只需要在实际总数上加上总数的4%。这就是我的
/* EXISTING WORKING TOTAL CODE */
$(function () {
$('.DoPricing').on("keyup",function () {
var total = 0;
$('.DoPricing').each(function () {
total += parseFloat($(this).val()) || 0;
});
$('#TotalPrice').html('$' + total);
});
});
/* NEW PERCENTAGE CODE BELOW THAT NEEDS INTEGRATED */
/* The code below is suppose to add 4% to total once integrated*/
var total = round_decimals(order_total, 2);
frm.TOTAL.value = total + ((4/100)*total);
var total = 200;
total = total*1.04;
console.log(total); // 208
所以在你的情况下
$(function () {
$('.DoPricing').on("keyup",function () {
var total = 0;
$('.DoPricing').each(function () {
total += parseFloat($(this).val()) || 0;
});
$('#TotalPrice').html('$' + (total*1.04).toFixed(2));
});
});
总计 200 将输出 208.00。
我已经设置了一个 javascript 代码来给出总数。我只需要在实际总数上加上总数的4%。这就是我的
/* EXISTING WORKING TOTAL CODE */
$(function () {
$('.DoPricing').on("keyup",function () {
var total = 0;
$('.DoPricing').each(function () {
total += parseFloat($(this).val()) || 0;
});
$('#TotalPrice').html('$' + total);
});
});
/* NEW PERCENTAGE CODE BELOW THAT NEEDS INTEGRATED */
/* The code below is suppose to add 4% to total once integrated*/
var total = round_decimals(order_total, 2);
frm.TOTAL.value = total + ((4/100)*total);
var total = 200;
total = total*1.04;
console.log(total); // 208
所以在你的情况下
$(function () {
$('.DoPricing').on("keyup",function () {
var total = 0;
$('.DoPricing').each(function () {
total += parseFloat($(this).val()) || 0;
});
$('#TotalPrice').html('$' + (total*1.04).toFixed(2));
});
});
总计 200 将输出 208.00。