大佬教程收集整理的这篇文章主要介绍了如何通过使用jquery添加该表的行来获取表总数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<table> <tr style="BACkground:#2b2e76"> <th colspan="1" style="padding: 0;"> <p style="color:white"> Table One </p> </th> <th> <p style="color:white" class="BundleB4936" id="B4936">@R_794_10586@l : <span class="BundelRow@R_794_10586@lB4936">1400.00</span></p> </th> </tr> <tr> <td> <input type="text" value="200.00" name="row_@R_794_10586@l[]" id="row@R_794_10586@l11_B4936" class="row@R_794_10586@l"> </td> </tr> <tr> <td> <input type="text" value="1200.00" name="row_@R_794_10586@l[]" id="row@R_794_10586@l12_B4936" class=" row@R_794_10586@l"> </td> </tr> </table> <table> <tr style="BACkground:#2b2e76"> <th colspan="1" style="padding: 0;"> <p style="color:white"> Table Two </p> </th> <th> <p style="color:white" class="BundleB1027" id="B1027">@R_794_10586@l : <span class="BundelRow@R_794_10586@lB1027">1750.00</span></p> </th> </tr> <tr> <td> <input type="text" value="100.00" name="row_@R_794_10586@l[]" id="row@R_794_10586@l16_B1027" class="row@R_794_10586@l"> </td> </tr> <tr> <td> <input type="text" value="250.00" name="row_@R_794_10586@l[]" id="row@R_794_10586@l17_B1027" class="row@R_794_10586@l"> </td> </tr> </table>
我的jquery:
var Bsum = 0; var BundelID = ''; $(".row@R_794_10586@l").each(function() { var RowID = $(this).attr('id'); var suffix = RowID.match(/\d+/)[0]; BundelID = $('.bundleB' + suffiX).attr('id'); if (RowID.indexOf(BundelID) != -1) { var BValue = $('#' + RowID).val(); if (!isNaN(Bvalue)) { Bsum += parseFloat(Bvalue); } } $('.bundelRow@R_794_10586@l' + BundelID).html(parseFloat(Bsum).toFixed(2)); });
这是我得到的输出
但我希望输出应该如下所示
有任何建议请!
谢谢.
注 – >更改的行被评论.
更新
$("table").each(function() { var Bsum = 0; var BundelID = ''; $(this).find(".row@R_794_10586@l").each(function() { var RowID = $(this).attr('id'); //var suffix = RowID.match(/\d+/)[0]; var suffix = RowID.split("_")[1]; console.log(suffiX) BundelID = $('.bundle' + suffiX).attr('id'); console.log(BundelID); if (RowID.indexOf(BundelID) != -1) { var BValue = $('#' + RowID).val(); if (!isNaN(Bvalue)) { Bsum += parseFloat(Bvalue); } } console.log(Bsum); $('.bundelRow@R_794_10586@l' + BundelID).html(parseFloat(Bsum).toFixed(2)); }); });
以上是大佬教程为你收集整理的如何通过使用jquery添加该表的行来获取表总数全部内容,希望文章能够帮你解决如何通过使用jquery添加该表的行来获取表总数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。