我需要打印 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();
问题是我使用了 3 个 css 文件
Custom.min.css
bootstrap.min.css
components.min.css
在我的打印输出中,我似乎无法应用这些样式。打印出来的是原始的。如何应用 CSS?
最佳答案
printWindow.document.write('<link rel="stylesheet" type="text/css" href="style/print.css"/>')
这包括 print.css。
对其他 css 文件执行相同的操作,并使用正确的文件路径
关于javascript - 将 CSS 应用于 printWindow.print();在 JavaScript 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37318538/