【发布时间】: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