1 局部打印方法:
作用:將id為dayin的內(nèi)容,新建頁面并打印,可解決打印某頁面中的部分內(nèi)容的問題。
使用方法:將要打印的內(nèi)容通過 <span id="dayin"></span>包含起來,然后在某個按扭中定義
事件
<input type="button" onclick="dayin()" value="打印">
function dayin()
{
var code="<body onload=window.print()>"
code+=document.all.dayin.innerHTML;
code=code.toUpperCase();
code=code.replace(/<A[^>]*>刪除</A>/gi, "");
code=code.toLowerCase();
var newwin=window.open('','','');
newwin.opener = null;
newwin.document.write(code);
newwin.document.close();
}
其中code=code.replace(/<A[^>]*>刪除</A>/gi, "");
2 利用CSS實現(xiàn)局部打印
介紹兩個關(guān)鍵的CSS
<style media="print">
.Noprint { DISPLAY: none }
.PageNext{ PAGE-BREAK-AFTER: always }
</style>第一個在不需要打印的標(biāo)簽上添加(子標(biāo)簽也將不被打印),第二個在需要換行的標(biāo)簽處添加(該標(biāo)簽所表示的內(nèi)容將在當(dāng)前打印的一頁內(nèi))
接下來通過調(diào)用最基本的js語句
window.print()就可實現(xiàn)頁面局部打印了,很easy吧!
3 打印預(yù)覽
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
height=0 id=wb name=wb width=3></OBJECT>
<input class="ipt" type=button name= button _print value="打印"
onclick =" javascript :printit();">
<input class="ipt" type=button name=button _setup value="打印頁面設(shè)置"
onclick =" javascript : printsetup();">
<input class="ipt" type=button name=button_show value="打印預(yù)覽"
onclick="javascript:printpreview();">
<input class="ipt" type=button name= button _fh value="關(guān)閉"
onclick =" javascript:window.close();">