【问题标题】:Can I Modify this Javascript to Print Images from Div?我可以修改此 Javascript 以从 Div 打印图像吗?
【发布时间】:2011-10-04 04:52:55
【问题描述】:

我的页面布局中有一个要打印的 div。我已经完成了一些关于如何做到这一点的示例代码,并提出了以下内容:

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

function PrintElem(elem)
{
    Popup($(elem).text());
}

function Popup(data) 
{
    var mywindow = window.open('', 'print_div', 'height=400,width=600');
    mywindow.document.write('<html><head><title>Print Window</title>');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');
    mywindow.document.close();
    mywindow.print();
    return true;
}

</script>

然后在 HTML 的正文中放置以下按钮:

<input type="button" value="Print Division" onclick="PrintElem('#print_div')" />

这对于在页面上创建基于文本的内容的快速打印非常有用,但我需要它做的是打印出页面上显示的图像。我可以更改此脚本来执行此操作吗?

【问题讨论】:

  • 我忽略了一个事实,即有一个 id=print_div 的 div 可以显示图像。

标签: javascript jquery image html printing


【解决方案1】:

你就不能这样做吗:

function PrintElem(elem)
{
    Popup($(elem).html());
}

参考:http://api.jquery.com/html/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 2019-11-28
    • 2010-09-22
    • 2021-10-22
    • 1970-01-01
    相关资源
    最近更新 更多