我想打印 div 内容,同时保持 css 应用于 div 及其内部 html。
我正在使用 jQuery Print Element 但它剥离了 css。
最佳答案
怎么样
function printDiv(id) {
var html = "";
$('link').each(function() { // find all <link tags that have
if ($(this).attr('rel').indexOf('stylesheet') !=-1) { // rel="stylesheet"
html += '<link rel="stylesheet" href="'+$(this).attr("href")+'" />';
}
});
html += '<body onload="window.focus(); window.print()">+$("#"+id).html()+'</body>';
var w = window.open("","print");
if (w) { w.document.write(html); w.document.close() }
}
关于jquery - 如何打印保持CSS的div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14093262/