我在打印时要显示边框有问题。下面是我的编码:
button
<button class="btn btn-sm btn-primary">Print</button>
Table
<table id="table" class="table table-bordered table-condensed table-hover table-striped dataTable">
Javascript
$('.btn').click(function(){
var printme = document.getElementById('table');
var wme = window.open("","","width=900,height=700");
wme.document.write(printme.outerHTML);
wme.document.close();
wme.focus();
wme.print();
wme.close();
})
我的打印输出如下,在打印中没有表格边框显示:
我的HTML页面:
打印时CSS不会保留在新窗口中。您可以在document.write()方法中将一些CSS传递到新窗口
喜欢
$('.btn').click(function(){
var css = '<style type="text/css">' +
'table th, table td {' +
'border:1px solid #000;'
'}' +
'</style>'
var printme = document.getElementById('table');
var printDoc = css + printme.outerHTML; // note this added css
var wme = window.open("","","width=900,height=700");
wme.document.write(printDoc);
wme.document.close();
wme.focus();
wme.print();
wme.close();
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句