输出类似具有动态记录数的 rowspan 的内容

发布于 2024-09-13 11:57:53 字数 1505 浏览 1 评论 0原文

给定一个像这样的表:

Col 1  |  Col 2
  1         2
  1         3
  2         4

...第 1 列中可以是任意数量的 1、2 等。我想动态输出如下所示的内容:

<table>
    <tr>
        <td rowspan="2">
            1
        </td>
        <td>
            2
        </td>
    </tr>
    <tr>
        <td>
            3
        </td>
    </tr>
    <tr>
        <td rowspan="1">
            2
        </td>
        <td>
            4
        </td>
    </tr>
</table>

我的问题是,对于上面的 html,我会计算不同 1 的数量以找到适当的行跨度数,然后返回并迭代它们以获取 html 输出。我只是想知道是否有一种更简单/更快的方法来执行类似的操作,我可以迭代记录并在第 1 列中的下一行与最后一行的第 1 行不同时添加一些内容。

我读到的内容听起来像我可以只使用 rowspan="0" 作为第一条记录,并按 tbody 标签将组分开,如下所示:

<table>
    <tbody>
        <tr>
            <td rowspan="0">
                1
            </td>
            <td>
                2
            </td>
        </tr>
        <tr>
            <td>
                3
            </td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td rowspan="0">
                2
            </td>
            <td>
                4
            </td>
        </tr>
    </tbody>
</table>

...rowspan="0" 将只跨越它所包含的 tbody 部分。我还没有能够找到很多关于此方法的信息,但我无法让它在 IE 或 Firefox 中工作。那么有什么东西可以加快我的 html 渲染速度吗?提前致谢。

Given a table like this:

Col 1  |  Col 2
  1         2
  1         3
  2         4

...and could be any number of 1's, 2's, etc. in Col 1. I want to dynamically output something that would look like this:

<table>
    <tr>
        <td rowspan="2">
            1
        </td>
        <td>
            2
        </td>
    </tr>
    <tr>
        <td>
            3
        </td>
    </tr>
    <tr>
        <td rowspan="1">
            2
        </td>
        <td>
            4
        </td>
    </tr>
</table>

My issue is that, for the above html, I would have to count the number of distinct 1's to find the appropriate rowspan number, then go back and iterate through them for the html output. I was just wondering if there was an easier/quicker way to do something similar where I could just iterate through the records and add something once the next row in Col 1 is different than the last row's Col 1.

I read something that sounded like I could just use rowspan="0" for the first record, and divide the groups up by tbody tags like so:

<table>
    <tbody>
        <tr>
            <td rowspan="0">
                1
            </td>
            <td>
                2
            </td>
        </tr>
        <tr>
            <td>
                3
            </td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td rowspan="0">
                2
            </td>
            <td>
                4
            </td>
        </tr>
    </tbody>
</table>

...and the rowspan="0" would just span the tbody section it is contained in. I haven't been able to find much info on this method, and I couldn't get it to work in IE or Firefox. So is there anything along those lines that would speed up my html rendering? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2024-09-20 11:57:53

像这样尝试怎么样?

<table>
  <tbody>
      <tr>
          <td rowspan="10">
              1
          </td>
          <td>
              2
          </td>
      </tr>
      <tr>
          <td>
              3
          </td>
      </tr>
  </tbody>
  <tbody>
      <tr>
          <td rowspan="10">
              2
          </td>
          <td>
              4
          </td>
      </tr>
  </tbody>
</table>

至少在这张表上看起来它可以在 IE8 和 FF 3.6 中运行。我假设如果 rowspan="10" 在具有 3 行且有 2 个部分(第一行 2 行,第二行 1 行)的表上工作正常,那么 rowspan="10000" 也应该工作。

编辑:哦,是的,根据几个网站,rowspan="0" 到目前为止仅在 Opera 中可以正常工作。

How about trying like this?

<table>
  <tbody>
      <tr>
          <td rowspan="10">
              1
          </td>
          <td>
              2
          </td>
      </tr>
      <tr>
          <td>
              3
          </td>
      </tr>
  </tbody>
  <tbody>
      <tr>
          <td rowspan="10">
              2
          </td>
          <td>
              4
          </td>
      </tr>
  </tbody>
</table>

At least on this table it looked like it worked in IE8 and FF 3.6. I'm assuming that if rowspan="10" works fine on a table with 3 rows that has 2 sections (2 rows first, 1 row second) then rowspan="10000" should work as well.

Edit: oh yea, according to a couple of sites, the rowspan="0" works correctly so far only in Opera.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文