五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > 使用js打印局部頁面

使用js打印局部頁面

文章來源:365jz.com     點(diǎn)擊數(shù):2746    更新時(shí)間:2009-09-20 08:50   參與評(píng)論

Web打印有很多方式,水晶報(bào)表使用的恐怕比較多,但這東西是收費(fèi)軟件,老板說不能用:(。ie自帶的有Active控件,但火狐不支持。這里使用的是js操作dom方法對(duì)窗體指定標(biāo)記內(nèi)文字進(jìn)行打印,所以使用時(shí)需要定義相關(guān)的標(biāo)簽及其樣式(文字大小、字體之類)。

<script type="text/javascript">
///***********************
//
/打印指定區(qū)域頁面
//
/說明:obj–通過getElementById或其它方式獲取標(biāo)簽標(biāo)識(shí),打印此obj內(nèi)的文字
//
/開發(fā):王洪劍
//
/日期:2009-8-7
function startPrint(obj)
{
    
var oWin=window.open("","_blank");
    
var strPrint="<h4 style=’font-size:18px; text-align:center;’>打印預(yù)覽區(qū)</h4>\n";
    
    strPrint
=strPrint + "<script type=\"text/javascript\">\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 + "<hr size=’1′ />\n";
    strPrint
=strPrint + "<div id=\"content\">\n";
    strPrint
=strPrint + obj.innerHTML + "\n";
    strPrint
=strPrint + "</div>\n";
    strPrint
=strPrint + "<hr size=’1′ />\n";
    strPrint
=strPrint + "<div style=’text-align:center’><button onclick=’printWin()’ style=’padding-left:4px;padding-right:4px;’>打  印</button>
<button onclick='window.opener=null;window.close();'  style='padding-left:4px;padding-right:4px;'>關(guān)  閉</button></div>\n";
    oWin.document.write(strPrint);
    oWin.focus();
    oWin.document.close();
}

</script>

<button id="btnPrint" onclick="startPrint(document.getElementById(’content’))">打印內(nèi)容</button>
<div id="content">
    
<div style="font-size:12px;color:#333;">
    這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容這里是打印內(nèi)容
    
</div>
</div>

預(yù)覽效果:點(diǎn)擊此處

Tag標(biāo)簽: js,打印

如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答?。?點(diǎn)擊進(jìn)入論壇

發(fā)表評(píng)論 (2746人查看,0條評(píng)論)
請(qǐng)自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動(dòng)的言論。
昵稱:
最新評(píng)論
------分隔線----------------------------

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時(shí)間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號(hào)