gpt4 book ai didi

jquery - 更有效的建表方法?

转载 作者:行者123 更新时间:2023-12-01 03:50:49 25 4
gpt4 key购买 nike

我必须将表格的 html 发送到 html 到 pdf 转换器脚本。我的表必须由 <thead> 组成从表 1 中,<tfoot>从表3和<tbody>从表2.我正在将 html 与 jQuery 放在一起。这就是我所拥有的:

$(document).ready(function() {
var html = $('div.dataTables_scroll').html();//so that changes don't affect the main page
var h = $(html).find('thead')[0];
var f = $(html).find('tfoot')[1];
var b = $(html).find('tbody')[0];
var newtable = $('<table></table>').append(h, f, b);
var d = $('<div></div>').append(newtable);
$('#foo').val(d.html()); //to see what the html looks like
});

Here是整个事情的 JSFiddle。它工作得很好,但我认为应该有一种更优雅的方式。

想法?

最佳答案

这个怎么样:

var ctx = $( 'div.dataTables_scroll' )[0];

var html = [
'<table>',
'<thead>' + $( 'thead', ctx ).eq( 0 ).html() + '</thead>',
'<tfoot>' + $( 'tfoot', ctx ).eq( 1 ).html() + '</tfoot>',
'<tbody>' + $( 'tbody', ctx ).eq( 0 ).html() + '</tbody>',
'</table>'
].join( '' );

关于jquery - 更有效的建表方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8825526/

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