如何在打印中打印包括表格边框显示?

用户名

我在打印时要显示边框有问题。下面是我的编码:

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();
})

我的打印输出如下,在打印中没有表格边框显示:

输出2

我的HTML页面:

输出3希望有人可以帮助我解决。谢谢。

肯尼

打印时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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章