【问题标题】:How to print div content and css associated using Jquery or PHp如何打印使用 Jquery 或 PHp 关联的 div 内容和 css
【发布时间】:2012-06-22 08:24:10
【问题描述】:

我有一个类似的页面:

我需要将黄色 div 的内容打印到 pdf(或直接物理打印机)。 我需要像你看到的那样打印 div .. 也使用 css 样式.. 我该怎么做?我在其他帖子中看到他们只打印文本内容..

有人可以帮我吗?

【问题讨论】:

标签: php jquery html printing


【解决方案1】:

您可以为不同的设备类型分配不同的 CSS 属性。 例如:

<style type="text/css">
/* all devices */
@media all
{
  #content { display:block;}
}

/* printer specific CSS */
@media print
{
  #content { display:none;}
  #content div#yellow { display:block;}
}
</style>

要打印页面,您可以使用 javascript window.print() 方法:

<form>
<input type="button" value="Print this page" onClick="window.print()">
</form>

【讨论】:

  • 然后呢?如何打印内容?
  • 更新了回复。 Javascript window.print() 将完成这项工作。
【解决方案2】:

使用以下代码:

<script type="text/javascript">
        function CallPrint(strid) {
            var prtContent = document.getElementById(strid);
            var WinPrint = window.open('', '', 'letf=0,top=0,width=400,height=400,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(prtContent.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
     </script>


<a href="#" onclick="javascript:CallPrint('divID')">Print</a>

【讨论】:

    猜你喜欢
    • 2013-07-19
    • 2016-02-17
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 2011-06-23
    • 2018-06-24
    • 2020-03-24
    相关资源
    最近更新 更多