Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Javascript和CSS打印div标记中的内容_Javascript_Jquery_Html_Css - Fatal编程技术网

如何使用Javascript和CSS打印div标记中的内容

如何使用Javascript和CSS打印div标记中的内容,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在编写报告。这是动态报告,我想打印。我使用了下面的代码,它可以很好地工作,但它不会在报告中加载当前的css样式。如何将CSS样式添加到最终打印预览和打印输出 <button onclick="printcontent('Report-body')">Print</button> <script> function printcontent(el){ var restorepage=document.body.in

我正在编写报告。这是动态报告,我想打印。我使用了下面的代码,它可以很好地工作,但它不会在报告中加载当前的css样式。如何将CSS样式添加到最终打印预览和打印输出

<button onclick="printcontent('Report-body')">Print</button>

                     <script>
function printcontent(el){
var restorepage=document.body.innerHTML;

document.body.innerHTML=printcontent;
window.print();
document.body.innerHTML=printcontent;
}
        </script>
打印
函数打印内容(el){
var restorepage=document.body.innerHTML;
document.body.innerHTML=打印内容;
window.print();
document.body.innerHTML=打印内容;
}
在div标签中开发报表

尝试以下代码

 var divContents = document.body.innerHTML;
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write('<html><head><title>Title</title>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(divContents);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            printWindow.print();
var divContents=document.body.innerHTML;
var printWindow=window.open(“”,’高度=400,宽度=800’);
printWindow.document.write('Title');
printWindow.document.write(“”);
printWindow.document.write(divContents);
printWindow.document.write(“”);
printWindow.document.close();
printWindow.print();

我想您可能需要使用内联样式来打印它,我相信您现在有了隐含的外部样式表!!使用样式标记为什么不能从当前页面打印样式标记,并在普通链接标记中使用打印css文件?实际上无法使用样式标记,因为我使用了引导框架…根据我的要求无法使用此样式标记,因为此处附带了引导文件