gpt4 book ai didi

javascript - 将多列 html 表转换为单列以实现移动友好布局

转载 作者:太空狗 更新时间:2023-10-29 16:50:44 24 4
gpt4 key购买 nike

我有一个包含 3 列的表格。我想转换为单行。

enter image description here

both append.('</tr><tr>') and after.('</tr><tr>') do not work.

移动友好页面需要这样 -

enter image description here

感谢您的帮助!

http://jsfiddle.net/tZt3Q/

最佳答案

实现此目的的一种方法是使用 JQuery wrap 方法。请参阅 Wrap UnWrap

Demo

Demo W/O class

 $(document).ready(function () {
var tbl = $("table");
$('td','table').unwrap().each(
function () {
tbl.append($(this).wrap('<tr>').parent());
});
});

更简单的一个:

 $(document).ready(function () {
$('table').find('td').unwrap().wrap($('<tr/>'));
});

Fiddle

关于javascript - 将多列 html 表转换为单列以实现移动友好布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16043045/

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