標籤:function code head post cin script table nat php
網頁中報表的列印,是通過調用window對象中的print()方法實現列印功能的;
呼叫瀏覽器本身的列印功能實現列印
<a href="#" onclick="window.print()">列印</a>
主要頁面代碼:查詢nation表
<body> <table border="1" cellspacing="0" cellpadding="0"> <tr><th>代號</th><th>名稱</th></tr> <tbody id="neirong"></tbody> </table> <a href="#" onclick="window.print()">列印</a></body></html><script type="text/javascript"> $.ajax({ type:"post", url:"chuli.php", async:true, dataType:"TEXT", success:function(data) { var hang=data.split("|"); var str=""; for(var i=0;i<hang.length;i++) { var lie=hang[i].split("^"); str=str+"<tr><td>"+lie[0]+"</td><td>"+lie[1]+"</td></tr>"; } $("#neirong").html(str); } });</script>
處理頁面代碼
<?phpinclude("../../gongju/DBDA.class.php");$db=new DBDA();$sql="select * from nation";echo $db->StrQuery($sql);?>
以上的內容,是列印瀏覽器顯示頁面所有的內容,但往往很多內容是不需要列印的,所以要加控制,用css樣式控制列印內容
<style>@media print { .noprint { display: none } } </style></head><body><p>我是需要列印的內容。但是不想列印出按鈕</p><button class="noprint" onclick="window.print()">列印文本</button></body>
php部分:網頁中報表的列印