简体   繁体   English

打印行数高于每个表

[英]Printing rows count above each table

I need your help and assistant in viewing the number of rows on each printed table at the top of it. 在查看每个打印表顶部的行数时,我需要您的帮助和助手。

I am using the below code to get the rows count: 我正在使用以下代码来获取行数:

    function count()
    {

    var tables = document.getElementsByClassName("tablesorter");
    var rows;
    for (var i = 0; i < tables.length; i++) {
      rows = tables[i].rows.length-1;
      alert(rows);
      span.innerHTML = rows;
    }

Currently the rows number are displayed in alerts and I want the number of the rows to be displayed in the html. 当前行号显示在警报中,我希望在html中显示行数。 I am printing the tables through while loop based on the retrieved values from the DB and they are having the same class and name. 我正在根据数据库中检索到的值通过while循环打印表,它们具有相同的类和名称。 The class name is tablesorter and the id is detailsid . 类名是tablesorter,id是detailsid。

I tried to print the number of the rows in the span, however it prints only above the first table. 我尝试打印跨度中的行数,但是它仅打印在第一个表上方。 It prints first 22 and then it was overwrited with 30 where the 30 should be printed above the second table. 它先打印22,然后用30覆盖,其中30应该打印在第二张表上方。 Here is my code for printing 这是我的打印代码

<%
while (rs.next())
        {

        count=0;
        name=rs.getString("name");   

        if (!(subcategory_name1).equals(temp_subcategory_name) )
            {
            i=0;                         
%>
<span id='span'></span>
<table class="tablesorter" id="detailsTable" width="80%">
<b>
<font style="font-size: 9pt" face="Arial" color="#162650"><%=category_name1%> / <%=subcategory_name1%> </font>
</b>
           <thead>
        <tr>
            <th>No.</th>
            <th>Name</th>
        </tr>
    </thead>
<%
}
%>
        <tbody>
<tr>
            <td><%=i%></td>
            <td align=left><%=name%></td>
</tr>
</tbody>

Kindly assit me in printing the number of the rows above each table 请帮我打印每个表格上方的行数

As i can see your code you are first assigning the 如我所见,您首先要分配

rows = tables[i].rows.length-1; 行=表[i] .rows.length-1;

and then using it to assign rows to span so every time it changes it will be reflected in all the spans 然后使用它来分配要跨度的行,因此每次更改它都会反映在所有跨度中

so you can directly assign the value tables[i].rows.length-1; 因此您可以直接分配值tables[i].rows.length-1; to the span 到跨度

no need to use a variable row 无需使用可变行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM