我可以修改这个Javascript从Div打印图像

Can I Modify this Javascript to Print Images from Div?

本文关键字:Div 打印 图像 Javascript 修改 我可以      更新时间:2023-09-26

我有一个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')" />

这对于在页面上创建基于文本的内容的快速打印非常有用,但我需要它做的是打印出正在显示在页面上的图像。我可以修改这个脚本来做到这一点吗?

你就不能这样做:

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

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