過程很簡單:
首先在asp.net頁面中設定開始打印和結束打印的標記,為了確保該標記不在網頁瀏覽時顯示,我們采用"<!-- HTML注釋 -->"的方式。比如:<!--startprint-->和<!--endprint-->。
接著寫相關的JavaScript代碼,具體代碼見后。
如果不想打印按鈕也被打印出來,注意將打印按鈕包含在<!--startprint-->和<!--endprint-->之外。
相關代碼:
代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AppealPrint.aspx.cs" Inherits="Appeal.AppealPrint"
MasterPageFile="MasterPage.master" Title="訴求打印" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="server">
<!--startprint-->
<style type="text/css">
body,table{
font-size:12px;
}
table{
table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
margin:0 auto;
}
td{
height:20px;
}
h1,h2,h3{
font-size:12px;
margin:0;
padding:0;
}
table{
border:1px solid #cad9ea;
color:#666;
}
table th{
height:30px;
}
table td,table th{
border:1px solid #cad9ea;
padding:0 1em 0;
}
table tr{
background-color:#f5fafe;
}
</style>
<table class="border" cellspacing="0" cellpadding="2" style="margin: 0px auto; width: 98%;border:1px solid;border-collapse:collapse;" id="TabBtnPrint">
<tbody>
<tr align="center">
<td class="title"><strong>訴 求 信 息</strong></td>
</tr>
<tr>
<td style="height: 25px">
<table cellspacing="1" cellpadding="2" style="margin: 0px auto; width: 100%;border-collapse:collapse;">
<tbody>
<tr class="tdbg">
<td width="30%" align="right" nowrap="nowrap">訴求主題:</td>
<td colspan="3">
新聞熱點
疑難解答
圖片精選