我正在尝试打印包含 css 的特定 div。我尝试了下面的代码,但是当我添加 css 行时,它打印出一个空白页,根本没有任何内容。删除 css 行打印没有任何 css 的页面。
function PrintElem(elem){
Popup($('<div/>').append($(elem).clone()).html());
}
function Popup(data){
var mywindow = window.open();
mywindow.document.write('<html><head><title>my div</title>');
mywindow.document.write('<link rel="stylesheet" href="./css/casestudy.css" type="text/css">');
mywindow.document.write('<link rel="stylesheet" href="./css/side-menu.css" type="text/css">');
mywindow.document.write('</head><body>');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
}
我该如何解决这个问题。我想打印所有包含的 css。
最佳答案
你可以试试css
<style type="text/css">
@media print {
body * { visibility: hidden; }
.printme* { visibility: visible; }
.printme { position: absolute; top: 40px; left: 30px; }
}
</style>
关于JavaScript 使用 Css 打印特定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39870744/