我有一个包含2列的表,其中“Give value”和其他列的“Take value”。我必须计算总给定值和总值。对于Take值,它很容易,因为它是表中记录的总数。现在我必须使用JavaScript / jquery计算Take值的总数。我该怎么做?用于计算表中的记录总数(即总给定值),如下所示
DIM giveOrTotal, assignrows, giveValue, takeValue
'############ Convert it to an array ##########
giveOrTotal = RsO.GetRows
'####### Get number of rows
giveValue = ubound(giveOrTotal,2)
Response.Write "<table>"
Response.Write"<tr><td>Currently Given: "& giveValue + 1 &"  Given Value</td>"
Response.Write"<tr><td>Currently Taken: "& takeValue + 1 &"  Taken Value</td>"
Response.Write "<table>"
现在我正在尝试计算所取值。我可以使用javascript进行吗?
答案 0 :(得分:0)
添加类和数据属性以存储行值
Response.Write "<table>"
Response.Write"<tr><td class='give-class' data-value='"& giveValue &"'>Currently Given: "& giveValue + 1 &"  Given Value</td>"
Response.Write"<tr><td class='take-class' data-value='"& takeValue &"'>Currently Taken: "& takeValue + 1 &"  Taken Value</td>"
Response.Write "<table>"
然后在JS循环遍历行和每个类的总和
$(function(){
var totals = {take: 0, give: 0};
$('tr').each(function(){
var $tds = $(this).children();
totals.take += +$tds.filter('.take-class').data('value');
totals.give += +$tds.filter('.give-class').data('value');
});
alert(totals.give);
});