gpt4 book ai didi

javascript - 是否可以在单元格之间旋转(交替)表格内容?

转载 作者:行者123 更新时间:2023-11-29 22:01:41 24 4
gpt4 key购买 nike

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

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

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

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

这是我正在尝试实现的示例:

enter image description here

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>

最佳答案

我会使用 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

关于javascript - 是否可以在单元格之间旋转(交替)表格内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23405934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com