将CSS应用于printWindow.print();在Javascript中

将CSS应用于printWindow.print();在Javascript中,javascript,html,twitter-bootstrap,css,Javascript,Html,Twitter Bootstrap,Css,我需要打印HTML页面中的一个部分。我使用下面的JS方法来打印它 printWindow.print(); 我就是这样做的 $("#toprint").on("click", function () { var divContents = $("#tobebilled").html(); var printWindow = window.open('', '', 'height=400,width=800'); printWindow.doc

我需要打印HTML页面中的一个部分。我使用下面的JS方法来打印它

printWindow.print();
我就是这样做的

$("#toprint").on("click", function () {

            var divContents = $("#tobebilled").html();
            var printWindow = window.open('', '', 'height=400,width=800');

printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>'); 
            printWindow.document.write('<html><head><title>Print Bill</title>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(divContents);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            printWindow.print();
在我的打印输出中,我似乎没有应用这些样式。打印出来的是未经加工的。如何应用CSS?

printWindow.document.write(“”)
printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>')
这包括print.css

对具有正确路径的其他css文件执行相同操作

printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>')