我可以修改此Javascript来打印Div的图像吗?

cod*_*pia 0 html javascript printing jquery image

我的页面布局中有一个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>
Run Code Online (Sandbox Code Playgroud)

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

<input type="button" value="Print Division" onclick="PrintElem('#print_div')" />
Run Code Online (Sandbox Code Playgroud)

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

Jam*_*ury 6

你不能这样做:

function PrintElem(elem)
{
    Popup($(elem).html());
}
Run Code Online (Sandbox Code Playgroud)

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