使用javascript的打印功能打印弹出窗口

时间:2013-05-16 07:45:06

标签: javascript jsp

我有一个模态弹出窗口“gatepass”。当我点击生成时,它会生成此门限。在这个gatepass中,我有两个按钮关闭并打印。当我点击打印按钮时,我想要打印gatepass而不是背景。请指导我,我该怎么办?

<html>
<head>
 <script src="js/calculateamt.js" type="text/javascript"></script>
      <link href="CSS/popup.css" rel="stylesheet" type="text/css">

</head>
<body>
   <fieldset id="gatepass" class="popup">
    <p align="center"><span style="size: 40px; font-size: 24px; alignment-adjust:middle">CASH RECIEPT</span></p>
    <table width="453" border="0" align="center" cellpadding="20px">
            <tr>
                <td width="188" height="51">RECIEPT NO : 
                    <label id="recno"><%=recieptno%></label></td>
                <td width="179">DATE : <label id="date"><%=date%></label></td>
            </tr>
            <tr>
                <td height="57">NAME : <label id="name" > <%=firstname%> <%=lastname%></label></td>
                <td>VILLAGE : <label id="village"> <%=vill%></label></td>
            </tr>
        </table>

        <p>&nbsp;</p>
        <table width="697" height="52" border="0" align="center" cellpadding="20px">
            <tr>
                <td width="205">AGREEMENT NO : <label id="agrno"> <%=agreno%></label> </td>
                <td width="149">LOT NO : <label id="lotno"><%=agreno%>/<%=bag%></label></td>
                <td width="151">BAGS : <label id="bags" ><%=bag%></label></td>
                <td width="174"> VEHICLE NO : <label id="vehicle"></label></td>
            </tr>
        </table>
        <p>&nbsp;</p>
        <table width="200" height="47" border="0" align="center" cellpadding="20px">
            <tr>
                <td> TOTAL AMOUNT : 
                    <label onloadstart="javascript:totalamt()" id="Totalamt" name ="total"></label></td>

            </tr>
        </table>
        <p align="center">
        <p align="center">
            <input type="button" name="Print" id="Print" value="PRINT" onClick="window.focus();window.print();">
            <input type="button" name="close" id="close" value="CLOSE" onClick = "closePopup();"  /> 

        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>

    </fieldset>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我建议您研究打印样式表

http://www.webdesignerdepot.com/2010/01/10-tips-for-better-print-style-sheets/

<link rel="stylesheet" type="text/css" href="print.css" media="print" />