作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须将表格的 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/
我是一名优秀的程序员,十分优秀!