js打印jsp页面的表单

一、给jsp表单页面需要打印的内容加id,调用js方法,注意:content是jsp里面div的id

onclick="startPrint(document.getElementById('content'));”

二、js函数

function startPrint(obj)

{
var oWin=window.open("","_blank");

    var strPrint="<h4 style='font-size:18px;border:0px; text-align:center;' width=730>付款申请表</h4>\n";
    /***************styleStart***************************/
    strPrint=strPrint + "<style type=\"text/css\" media=print>\n";

    strPrint=strPrint + "\.noprint{display : none }\n";

    strPrint=strPrint + "<\/style>\n";
    
    /*****************styleEnd************************/
    strPrint=strPrint + "<script type=\"text/javascript\">\n";
    
    strPrint=strPrint + "\window.onload=function(){\n";
    strPrint=strPrint + "\document.getElementById(\"up1\").style.fontSize = \"12px\"\n";
    strPrint=strPrint + "\document.getElementById(\"t\").style.fontSize = \"12px\"\n";
    strPrint=strPrint + "\document.getElementById(\"makeFlowIdNoGroup\").style.fontSize = \"12px\"\n";
    
    strPrint=strPrint + "\}\n";

    strPrint=strPrint + "function printWin()\n";

    strPrint=strPrint + "{";

    strPrint=strPrint +    "var oWin=window.open(\"\",\"_blank\");\n";

    
    strPrint=strPrint + "oWin.document.write(document.getElementById(\"content\").innerHTML);\n";
    
    strPrint=strPrint + "oWin.focus();\n";

    strPrint=strPrint + "oWin.document.close();\n";

    strPrint=strPrint + "oWin.print()\n";

    strPrint=strPrint + "oWin.close()\n";

    strPrint=strPrint + "}\n";

    strPrint=strPrint + "<\/script>\n";


    strPrint=strPrint + "<table id=\"content\" style='font-size:12px;margin-top:-20px' border=1 cellSpacing=0 cellPadding=0 width=730>\n";

    strPrint=strPrint + obj.innerHTML + "\n";

    strPrint=strPrint + "</table>\n";

    strPrint=strPrint + "<hr size='1' class='noprint' />\n";

    strPrint=strPrint + "<div  class='noprint' style='text-align:center'><button onclick='print();' style='padding-left:4px;padding-right:4px;'>打  印</button><button onclick='window.opener=null;window.close();'  style='padding-left:4px;padding-right:4px;'>关  闭</button></div>\n";

    oWin.document.write(strPrint);

    oWin.focus();

    oWin.document.close();


}



 

你可能感兴趣的:(js打印jsp页面的表单)