gpt4 book ai didi

jquery - 打印特定的 div 和表格

转载 作者:行者123 更新时间:2023-12-01 07:57:08 24 4
gpt4 key购买 nike

我现在的代码是这样的:

function printPage() {
var prtContent = document.getElementById("data");
alert(prtContent.toSource());
var WinPrint = window.open('', '', 'letf=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}

现在打印的 div 是数据。数据中有一个表格,但是当我尝试打印它时,它没有显示为表格。我怎样才能将其编写为打印表格的代码?

我的第二个问题是我有另一个名为 title 的 div。我也想将其打印在表格上方。真心希望有人能帮助我。

最佳答案:

因此,最好和最简单的方法是创建一个打印 css 文件并将其链接到您的页面中,例如在标题中使用:

<link rel="stylesheet" type="text/css" href="print.css" media="print">

CSS 文件示例:

.class, #divId { display:none; }

检查您是否应用到正确的 div id 或类名的最简单方法是检查浏览器中的 css 组件并在其中添加 css 规则。

最佳答案

这是一个更好的方法

<link rel="stylesheet" type="text/css" href="print.css" media="print">

在 css 中隐藏您不想打印和显示的所有内容的“display:none”这就像一个魅力。

关于jquery - 打印特定的 div 和表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23416306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com