日期:2014-05-17  浏览次数:20424 次

如何使用js对Repeater生成的table进行列和统计?
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse; width:400px;">
  <tr align="center" style="height:25px;">
  <th style="width:50px; line-height:120%;">序号</th>
  <th style="width:150px; line-height:120%;">样文</th>
  <th style="width:200px; line-height:120%;">录入列</th>
  </tr>

  <asp:Repeater ID="Repeater1" runat="server" 
  onitemdatabound="Repeater1_ItemDataBound">
  <ItemTemplate>
  <tr align="right" style="height:25px;">
  <td align="center"><%# DataBinder.Eval(Container.DataItem, "ptsjtmmx_xh")%></td>
  <td id="s1" style="padding-right:5px;"><%# DataBinder.Eval(Container.DataItem, "ptsjtmmx_je")%></td>
  <td align="right"><input id="txtJE" type="text" t_value="" o_value="" style="width:200px; border:0px none white; height:25px; text-align:right;" onKeyPress="fkeyPress(this);" onkeyup="fkeyUp(this);" /></td>
  </tr>
  </ItemTemplate>
  </asp:Repeater>

  <tr align="center" style="height:25px;">
  <td style="width:50px; line-height:120%;">合计:</td>
  <td id="Sum1" style="width:150px; line-height:120%;"></td>
  <td id="Sum2" style="width:200px; line-height:120%;"></td>
  </tr>
  </table>

------解决方案--------------------
js DOM进行 啊

document.getElementById("设置个tableID").rows[i].cells[j]得到各个单元格,累加就可以了
------解决方案--------------------
HTML code
    <script type="text/javascript">
        $(document).ready(function () {
            $("#tbid tr:last td:eq(0)").html("合计:" + ($("#tbid tr").length - 2));
            var val1 = 0;
            var val2 = 0;
            $("#tbid tr:gt(0)").not(":last").each(function () {
                val1 += parseInt($(this).find("td:eq(1)").html());
                val2 += parseInt($(this).find("td:eq(2)").html());
            })
            $("#tbid tr:last td:eq(1)").html(val1);
            $("#tbid tr:last td:eq(2)").html(val2);
        })
    </script>

    <div>
        <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse; width: 400px;" id="tbid">
            <tr align="center" style="height: 25px;">
                <th style="width: 50px; line-height: 120%;">序号</th>
                <th style="width: 150px; line-height: 120%;">样文</th>
                <th style="width: 200px; line-height: 120%;">录入列</th>
            </tr>
            <tr align="center" style="height: 25px;">
                <td style="width: 50px; line-height: 120%;">12</td>
                <td styl