你不应该更换整个页面的HTML,因为这会删除所有点击处理程序(用于处理例如标签的那些)
要打印,你应该做到以下几点:
- 创建一个高于一切显示一个div(固定的,高度/宽度:100%,顶端/左:0)
- 隐藏在主体
- 一切添加所述内容将被打印到第Ë格
- 呼叫打印
- 删除DIV
- 恢复身体状态
喜欢的东西:
JS
function printReport() {
var $printerDiv = $('<div class="printContainer"></div>'); // create the div that will contain the stuff to be printed
$printerDiv.html(divElements); // add the content to be printed
$('body').append($printerDiv).addClass("printingContent"); // add the div to body, and make the body aware of printing (we apply a set of css styles to the body to hide its contents)
window.print(); // call print
$printerDiv.remove(); // remove the div
$('body').removeClass("printingContent");
}
CSS
body.printingContent > *{
display: none !important; /* hide everything in body when in print mode*/
}
.printContainer {
display: block !important; /* Override the rule above to only show the printables*/
position: fixed;
z-index: 99999;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
你能更详细地了解'window.print();'后面会发生什么吗?您无法点击“其他标签” - 是因为网页上的以前的内容没有显示,或者因为它显示,但不是不响应点击? – ASGM 2013-05-10 08:23:12
如果我关闭打印窗口或点击打印选项,然后打印窗口将关闭并显示我的页面,但之后在我的页面我无法点击任何标签或按钮等 – Prashobh 2013-05-10 08:28:04