最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

web打印 window.print()介紹

 更新時間:2013年05月06日 10:26:53   作者:  
web打印 window.print()介紹,需要的朋友可以參考一下

 我只給出比較有效的,方便的打印方法,有些WEB打印是調(diào)用ActiveX控件的,這樣就需要用戶去修改自己IE瀏覽器的Internet選項里的安全里的ActiveX,將它們?nèi)繂⒂?,有些麻煩,翻了下網(wǎng)絡(luò),下面的方法是可以直接打印,而不會去修改IE的Internet選項。

window.print來打印頁面,頁面上別的元素也會被打印處理,頁頭頁尾的格式也不好控制。
• 常用方法:大部分情況會把查詢的結(jié)果綁定到DataGrid上來,然后打印DataGrid。這種情況的打印一般來說格式比較固定簡單,確定后基本不會再作更改。所以可以采用IE直接打印。

【實例代碼】
注:①這是客戶端通過window.print打印指定內(nèi)容。這里定義sprnstr和eprnstr來指定內(nèi)容
     執(zhí)行代碼:

復(fù)制代碼 代碼如下:
    
<input type="button" name="print" value="http://www.fzitv.net/yc1990/archive/2012/03/03/預(yù)覽并打印" onclick="preview()">
   
②如果直接使用window.print將打印頁面上的所有內(nèi)容,但是我們可以使用
<style> @media Print { .Noprn { DISPLAY: none }}
是用來指定不打印的內(nèi)容。

復(fù)制代碼 代碼如下:

<script language="Javascript">
function preview()
{
    bdhtml=window.document.body.innerHTML;
    sprnstr="<!--startprint-->";
    eprnstr="<!--endprint-->";
    prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
    prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
    window.document.body.innerHTML=prnhtml;
    window.print();
}
</script>
<!--省略部分代碼-->
<form id="WebForm1" method="post" runat="server">
     <center>本部分以上不被打印</center>
     <!--startprint-->
     <div align="center">
         <asp:DataGrid id="dgShow" runat="server">
              <!--省略部分代碼-->
         </asp:DataGrid>
     </div>
     <!--endprint-->
     <center>本部分以下不被打印</center>
     <div align="center">
         <input type="button" name="print" value="http://www.fzitv.net/yc1990/archive/2012/03/03/預(yù)覽并打印" onclick="preview()">
     </div>
     <style> @media Print { .Noprn { DISPLAY: none }}
     </style>
     <p class="Noprn">不打印</p>
     <table id="datagrid">
         <tr>
              <td>打印</td>
         </tr>
     </table>
     <input class="Noprn" type="button" onclick="window.print()" value="http://www.fzitv.net/yc1990/archive/2012/03/03/print">
</form>

    最主要的一句就是:
復(fù)制代碼 代碼如下:

<input class="Noprn" type="button" onclick="window.print()" value="http://www.fzitv.net/yc1990/archive/2012/03/03/print">

    這樣就可以打印了,通過設(shè)置CSS屬性,將很容易控制哪些需要打印,哪些不需要打印,而且這樣的打印是沒有附加的頁眉和頁碼的信息的。

相關(guān)文章

最新評論

游戏| 姜堰市| 蕲春县| 延安市| 开化县| 德清县| 榆中县| 渝中区| 清镇市| 漳州市| 青阳县| 翁牛特旗| 高邑县| 石渠县| 凌海市| 兴文县| 浦城县| 仪陇县| 武邑县| 林州市| 大方县| 聂荣县| 河东区| 邵东县| 安宁市| 汉川市| 洱源县| 蒙阴县| 南郑县| 府谷县| 广宁县| 启东市| 冀州市| 马关县| 荣成市| 左权县| 凤冈县| 青阳县| 华池县| 仪陇县| 疏附县|