打印DIV的内容 [英] Print the contents of a DIV
本文介绍了打印DIV的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打印DIV内容的最佳方法是什么?
解决方案对早期版本稍作修改 - 在CHROME
函数PrintElem(elem)
{
var mywindow = window.open('','PRINT' ,'height = 400,width = 600');
mywindow.document.write('< html>< head>< title> + document.title +'< / title>');
mywindow.document.write('< / head>< body>');
mywindow.document.write('< h1>'+ document.title +'< / h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('< / body>< / html>');
mywindow.document.close(); //必须为IE> = 10
mywindow.focus(); //需要IE> = 10 * /
mywindow.print();
mywindow.close();
返回true;
}
Whats the best way to print the contents of a DIV?
解决方案
Slight changes over earlier version - tested on CHROME
function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}
这篇关于打印DIV的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文