jQuery每个函数结果怎么办?

我必须构建一个表单,我一直在研究jQuery,但如果你能给我任何建议,我会陷入困境,

所以让我来解释一下我有20种产品的forms,包括offer1,offer2和月费,所有这些至今都是完美的工作我只需要你选择特定产品的数量,当你按下一个按钮显示再次结果,但只有数量填充所以基本上只有客户对他们感兴趣的产品,这里是我的主要问题,我知道我必须在jQuery每个function,但我不知道如何做到这一点?

我已将图片附加到表单,以便您可以看到示例表单图片

编辑:这是我目前的代码:

function convert(value) { return "" + ((Number(value) || 0).toFixed(2).replace(/(\d)(?=(\d{3})+ (?!\d))/g, "$1,")) + ""; } function testing(id, normaloffer, talesalesoffer, montlyoffer) { var normaoffertotal = normaloffer * $('#amount' + id).val(); var talesalestotal = talesalesoffer * $('#amount' + id).val(); var montlytotal = montlyoffer * $('#amount' + id).val(); $(".normaloffertotal" + id).html(normaoffertotal); $(".telesalesoffertotal" + id).html(talesalestotal); $(".montlytotal" + id).html(montlytotal); $('#hnoffer' + id).val(normaoffertotal); } console.log(convert(10496.470000000001)); function normaloffertotalcalc() { var sumnormaltotal = 0; $('span[id^="normaloffertotalspan"]').each(function () { var text = $(this).text(); sumnormaltotal += parseFloat(text, 10); }); $('#sumnormaltotal').html(sumnormaltotal); var sum_telesale = 0; $('span[id^="telesalesoffertotalspan"]').each(function () { var text = $(this).text(); sum_telesale += parseFloat(text, 10); }); $('#sumtelesaletotal').html(sum_telesale); var sum_montly = 0; $('span[id^="montlyofferspan"]').each(function () { var text = $(this).text(); sum_montly += parseFloat(text, 10); }); $('#summontlytotal').html(sum_montly); console.log('Normal Total Offer ' + convert(sum_normal)); console.log('TeleSales Total Offer ' + convert(sum_telesale)); console.log('Montly Total Offer ' + convert(sum_montly)); }  

这是html

    <input type="text" placeholder="0" id="amount" name="amount" onblur="normaloffertotalcalc()" onkeyup="testing(, , , )" style="-webkit-appearance: none; background: none; text-align: center; border: none; width: 40px;">  £ £<span class="normaloffertotal" id="normaloffertotalspan">0 <input type="hidden" class="normaloffertotalspan" id="hnoffer">  £ £<span class="telesalesoffertotal" id="telesalesoffertotalspan">0  £ £<span class="montlytotal" id="montlyofferspan">0   

我找到了解决这个问题的解决方案

  $('input[type=text]').each(function(){ var val = parseInt($(this).val()); if(val > 0){ var id = $(this).attr('id'); if(id){ console.log(id); } console.log(val); } }); 

这是我做的代码,并且工作正常:)

感谢所有给我建议的人

还有一件事,你有什么想法我怎么能从MySQL只导出那些id为2,7,1的产品:)