你可以在没有插件的情况下做到这一点。我不知道那个插件是否在做额外的事情。您将不得不编写一个自定义 js 函数来仅打印 div 而不是整个页面...
html
<div id="printDiv">
//content Here
</div>
js
function customPrint(id) {
var cont = $('#'+id).html(),
pageCont = $('body').children();// Updated
/*Replace the page content with the div content that needs to be printed*/
$('body').html(cont);
/*Print function call*/
window.print();
/*Place the original page content back*/
$('body').html(pageCont);
}
customPrint("printDiv");
更新
function customPrint(id) {
var cont = $('#'+id),
pageCont = $('body');
/*Hide the page content*/
pageCont.hide();
cont.show();
/*Print function call*/
window.print();
/*Display back the page content*/
pageCont.show();
}