打印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;
}

发表评论