gpt4 book ai didi

php - 我如何计算 Javascript 中多个产品的总量? AJAX 带来的值(value)

转载 作者:可可西里 更新时间:2023-11-01 14:03:43 25 4
gpt4 key购买 nike

$.ajax({
type: "POST",
url: 'ajax_subtotal.php',
data: listing_id=listId,
dataType:'json',
success: function(data)
{
if(data['result']=='success')
{
alert(data['pricing']);
}
}

data['pricing'] 给出了一种产品的价格。如果产品数量发生变化,该函数将被调用。那么,如何同时计算多个产品的总价呢??

最佳答案

First i store all the value in to the hidden field..

<input type="hidden" name="NumberOfProperty[]" id="NumberOfPropertyTxt<?php echo $id;?>" value=""/>

When my ajax is calling i got all the value in it..

var values=$('input[name="NumberOfProperty[]"]').map(function()
{
return this.value
}).get();
console.log(values);

In this i got my all price stored in to the array...then

var Total=0;
$('input[name="NumberOfProperty[]"]').each(function()
{
if($(this).val()>0)
{
Total+= parseFloat($(this).val());
}
});
$('#sub_total').val(Total);
$('#subtotal').html(Total);

I got all the value into the Total and assign it in to the sub_total id.

关于php - 我如何计算 Javascript 中多个产品的总量? AJAX 带来的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15963689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com