如何使用jQuery打印页面的一部分? [英] How to print a part of my page using jQuery?

查看:70
本文介绍了如何使用jQuery打印页面的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想打印页面的某些部分.我的示例代码如下:

I would like to print only certain part of my page. My sample code follows:

<%@ page contentType="text/html;charset=ISO-8859-1" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
        <title>Insert title here</title>    
    </head>
    <body>
        <div class="body">
            Blah... blah... 
        </div>
        <div class="printable">
           contents goes here...
        </div>
    </body>
</html>

我需要打印<div class="printable"></div>的内容.是否可以使用jQuery做到这一点?我应该写这个解决方案,还是有一个插件可以帮助解决这个问题?

I need to print the contents of <div class="printable"></div>. Is it possible to do this using jQuery? Should I write this solution, or is there a plugin that would help solve this problem?

推荐答案

添加到HTML标头:

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

print.css

body * { display: none; }
.printable { display: block; }

Javascript

window.print();

这篇关于如何使用jQuery打印页面的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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