如何使用jQuery打印页面的一部分?

如何使用jQuery打印页面的一部分?,jquery,jquery-plugins,Jquery,Jquery Plugins,我只想打印我页面的某些部分。我的示例代码如下: <%@ 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</titl

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

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

在此处插入标题
废话。。。废话。。。
内容放在这里。。。

我需要打印
的内容。使用jQuery可以做到这一点吗?我应该写这个解决方案,还是有一个插件可以帮助解决这个问题?

我没有从stackoverflow得到任何好的解决方案,所以我自己发布了答案

 <%@ 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>    
  <script type="text/javascript">
     printDivCSS = new String ('<link href="myprintstyle.css" rel="stylesheet" type="text/css">')
function printDiv(divId) {
    window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById(divId).innerHTML
    window.frames["print_frame"].window.focus()
    window.frames["print_frame"].window.print()
}
</head>
<body>
   <div class="body">
   Bla h......... blah... 
</div>
<div class="printable">
   contents goes here.........
</div>
<b></b> <a href=javascript:printDiv('printable')>Print This Div</a><br>

在此处插入标题
printDivCSS=新字符串(“”)
函数printDiv(divId){
window.frames[“print_frame”].document.body.innerHTML=printDivCSS+document.getElementById(divId).innerHTML
window.frames[“print_frame”].window.focus()
window.frames[“print_frame”].window.print()
}
诸如此类。。。。。。。。。废话。。。
内容放在这里。。。。。。。。。

请参阅:

添加到HTML标题: Javascript
我从未使用过它,但谷歌发现:2009年的答案是:
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
body * { display: none; }
.printable { display: block; }
window.print();