我的网页上有两个部分,SectionA和SectionB(2个HTML表格)。如何在javascript中打印页面的两个部分之一
我希望能够打印整个页面,只有SectionA或只有SectionB。
我已经有一个CSS文件media="print"
,我用window.print()
。
要打印整个页面,请使用浏览器打印按钮/菜单项。
只打印部1.:
function PrintSectionA()
{
$('#SectionA').removeClass('hideFromPrint');
$('#SectionB').addClass('hideFromPrint');
window.print();
}
和相对来说PrintSectionB()
呀!它工作...差不多。如果我尝试只打印SectionA,,然后整个页面,我只会得到SectionA,因为SectionB仍然有hideFromPrint类。
我会希望是:将文档发送到打印机
function PrintSectionA()
{
$('#SectionA').removeClass('hideFromPrint');
$('#SectionB').addClass('hideFromPrint');
window.print();
$('#SectionB').removeClass('hideFromPrint');
}
但window.print();
返回之前。所以PrintSectionA()
实际打印现在一切:(。
有没有一种方法,使工作?
我想我看见的地方,我可以强制CSS分页,我可以要求用户打印整个页面,但只能选择第一或第二页......没有乐趣!
也许更好的解决方案是创建两个CSS用于打印的文件,并且只是将链接更改为打印CSS文件吨或链接被点击。 – 2010-09-16 22:25:23