javascript - 我可以修改此 JavaScript 以从 Div 打印图像吗?

标签 javascript jquery image html printing

我的页面布局中有一个要打印的 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/

关于javascript - 我可以修改此 JavaScript 以从 Div 打印图像吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6674425/

相关文章:

php - 从 base64_encode 调整图像大小

javascript - 字符串解析器

javascript - 单击菜单切换时将菜单更改为登录

javascript - 在悬停时显示具有模糊/渐变边缘的图像部分

jquery - 如何使用 JavaScript 历史记录 API

jquery:简单的图像预加载器+ onload

javascript - 如何处理快速移动的鼠标而不触发 mousemove 事件

jquery - 具有复杂 JSON 的动态 html 表

javascript - 使用AJAX解析XML : Image Link : undefined?

html - 如何让我的图像在用 "visibility: hidden"消失后重新出现在悬停时?