【问题标题】:Is it possible to rotate (alternate) table content between cells?是否可以在单元格之间旋转(替代)表格内容?
【发布时间】:2018-07-30 18:52:17
【问题描述】:

我有一个带有 3 个单元格的 table,我想知道是否可以在每个单元格之间“旋转”数据?

基本上,所以在设定的时间后,我希望第一个单元格中的数据移动到第二个单元格,第二个单元格的数据移动到第三个单元格,第三个单元格的数据移动到第一个单元格,依此类推上...

我猜它是否可能需要某种形式的 JavaScript?

我愿意接受所有可能的解决方案

这是我想要实现的一个示例:

MY TABLE

<table class="three" width="150" height="35%" border="1"><tr>
<td colspan="2" align="center" valign="bottom" style="font-size:30px;"><strong>T/O: £48k</strong></td></tr>
<tr>
<td width="60" align="center" style="font-size:12px"><strong>GP:£7k</strong>
</td>
<td width="60" align="center" style="font-size:12px"><strong>M:15%</strong>
</td>
</tr>
</table>

【问题讨论】:

  • 如果你想在客户端做这个,你需要javascript。因此它将涉及到玩 DOM,使用 jquery 让您的生活更轻松。

标签: javascript css html-table


【解决方案1】:

我会使用 jQuery 来执行此操作,因为它需要对 DOM 进行操作。除此之外,我会将样式与标记分开。

// Store the TRs to a variable
var $tr = $('.three tr');

// Write a function
!function reDraw() {

    // Identify the TDs
    var $td1 = $tr.eq(0).find('td'),
        $td2 = $tr.eq(1).find('td').eq(0),
        $td3 = $tr.eq(1).find('td').eq(1);

    // Reshuffle TDs, and apply correct colspan
    $td2.insertBefore( $td1 ).attr('colspan','2');
    $td1.insertAfter( $td3 ).attr('colspan','1');

    // Refresh after 2 seconds
    setTimeout(reDraw, 2000);
}();

查看JS Fiddle

【讨论】:

  • 是的!这非常有效:) 非常感谢安德斯
  • 很高兴为您提供帮助 :) 希望您能在您的网站上使用它!
猜你喜欢
  • 2015-06-06
  • 2022-01-12
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 2019-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多