我可以修改这个Javascript从Div打印图像吗? [英] Can I Modify this Javascript to Print Images from Div?

查看:95
本文介绍了我可以修改这个Javascript从Div打印图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的页面布局中有一个div,我想打印。

 < script type =text我已经通过一些示例代码了解如何做到这一点,并提出以下建议: / javascriptsrc =http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js> < /脚本> 
< script type =text / javascript>

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


函数Popup(data)
{
var mywindow = window.open('','print_div','height = 400,width = 600' );
mywindow.document.write('< html>< head>< title>打印窗口< / title>');
mywindow.document.write('< / head>< body>');
mywindow.document.write(data);
mywindow.document.write('< / body>< / html>');
mywindow.document.close();
mywindow.print();
返回true;
}

< / script>

然后在HTML的主体中放置以下按钮:

 < input type =buttonvalue =Print Divisiononclick =PrintElem('#print_div')/> 

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

解决方案

难道你不能这样做:

 函数PrintElem(elem)
{
Popup($(elem).html());

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

I have a div in my page layout that I would like to print. I have worked through some sample code on how to do this and come up with the following:

<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>

Then in the body of the HTML I place the following button:

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

This works great for creating a quick print of the text based content on the page, but what I need it to do is print out the images that are being displayed on the page as well. Can I alter this script to do this?

解决方案

Couldn't you just do:

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

Reference: http://api.jquery.com/html/

这篇关于我可以修改这个Javascript从Div打印图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆