猿问

无法在Ajax计算表格中获得总计

我创建了这样的表单:

问题是我无法获得子总计字段的总计。


我尝试创建与总计总计相同的总计字段,但是没有运气。我想知道我是否犯了一个错误,即没有在全局范围内创建一些变量?有没有简单的解决方案可以做到这一点?您可以在这里找到完整的代码:http : //autopartsdiscountcoupons.com/table/Form.html


$("#con_qty116").bind('keyup mouseup', function() {

  var rate = 40;

  var qty = $("#con_qty116").val();

  var val = qty * rate;


  $("#con_qty116_td").text(val);

  sub_total_of_weather_sheild();

});


$("#con_qty117").bind('keyup mouseup', function() {

  var rate = 160;

  var qty = $("#con_qty117").val();

  var val = qty * rate;


  $("#con_qty117_td").text(val);

  sub_total_of_decorative_surface();


});


function sub_total_of_weather_sheild() {

  var td116 = parseInt($("#con_qty116_td").text());

  var sub_tot = td116;

  $("#weather_sheild_qty_sub_total").text(sub_tot);

  gr_total(sub_tot);

}


function sub_total_of_decorative_surface() {

  var td117 = parseInt($("#con_qty117_td").text());

  var sub_tot = td117;

  $("#decorative_surface_qty_sub_total").text(sub_tot);

}

  <td>116</td>

  <td>Provide and apply Weathershield (Reputable Brand) minimum...

  </td>

  <td>Sft</td>

  <td><input id="con_qty116" name="con_qty116" type="number" /></td>

  <td>40</td>

  <td id="con_qty116_td">0</td>

  <th colspan="4">Sub Total</th>

  <td id="weather_sheild_qty_sub_total" colspan="2">0</td>

  <td>117</td>

  <td>Color Crete min 4mm thickness including surface preparation applied on prepared surface using Applicant Machine/Gun

  </td>

  <td>Sft</td>

  <td><input id="con_qty117" name="con_qty117" type="number" /></td>

  <td>160</td>

  <td id="con_qty117_td">0</td>

</tr>

<tr>

  <th colspan="4">Sub Total</th>

  <td id="decorative_surface_qty_sub_total" colspan="2">0</td>

</tr>


<th colspan="4">Grand Total</th>

<th colspan="2" id="grand_total">0</th>


qq_遁去的一_1
浏览 129回答 2
2回答

慕娘9325324

在每个功能上,当您更新小计时,您还将获得每个小计,并将所有这些总和相加并放入小计。请按照以下步骤操作:-在grand_total()函数中获取每个小计的值function grand_total(){&nbsp; var grand_total = parseInt($("#ew_qty_sub_total").text());&nbsp; grand_total += parseInt($("#con_qty_sub_total").text());&nbsp; grand_total += parseInt($("#rein_qty_sub_total").text());&nbsp; .&nbsp; .&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; .&nbsp; &nbsp;&nbsp;grand_total += parseInt($("#weather_sheild_qty_sub_total").text());&nbsp;grand_total += parseInt($("#decorative_surface_qty_sub_total").text());&nbsp;$("#grand_total").text(grand_total);}&nbsp; &nbsp; &nbsp;在每个keyup / mouseup函数中调用此函数。像这样:-$("#ew_qty1").bind('keyup mouseup',function (){&nbsp; var rate = 12;&nbsp; // Take Quantity from user&nbsp; var qty = $("#ew_qty1").val();&nbsp; // Multiply Quantity By 10&nbsp; var val = qty*rate;&nbsp; // Set Text In TD&nbsp; $("#ew_qty1_td").text(val);&nbsp; sub_total_of_earth_Work();&nbsp; grand_total();&nbsp; &nbsp;//call for total of sub total&nbsp;});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答