js或jquery實(shí)現(xiàn)頁面打印可局部打印
更新時(shí)間:2014年03月27日 15:38:57 作者:
這篇文章主要介紹了js或jquery如何實(shí)現(xiàn)頁面打印也可局部打印,需要的朋友可以參考下
js或jquery實(shí)現(xiàn)頁面打印(局部打印)
1、js實(shí)現(xiàn)(可實(shí)現(xiàn)局部打?。?
<html>
<title>js打印</title>
<head></head><body>
<input id="btnPrint" type="button" value="打印" onclick="javascript:window.print();" />
<input id="btnPrint" type="button" value="打印預(yù)覽" onclick=preview(1) />
<style type="text/css" media=print>
.noprint{display : none }
</style>
<p class="noprint">不需要打印的地方</p>
<script>
function preview(oper)
{
if (oper < 10)
{
bdhtml=window.document.body.innerHTML;//獲取當(dāng)前頁的html代碼
sprnstr="<!--startprint"+oper+"-->";//設(shè)置打印開始區(qū)域
eprnstr="<!--endprint"+oper+"-->";//設(shè)置打印結(jié)束區(qū)域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //從開始代碼向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//從結(jié)束代碼向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
</script>
<p>XXXXX</p>
<!--startprint1-->要打印的內(nèi)容<!--endprint1-->
</body>
</html>
2、調(diào)用windows底層打印,報(bào)安全警告,不建議使用(不支持局部打?。?
<HTML>
<HEAD>
<TITLE>javascript打印-打印頁面設(shè)置-打印預(yù)覽代碼</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312" />
<SCRIPT language=javascript>
function printsetup(){
// 打印頁面設(shè)置
wb.execwb(8,1);
}
function printpreview(){
// 打印頁面預(yù)覽
wb.execwb(7,1);
}
function printit()
{
if (confirm('確定打印嗎?')) {
wb.execwb(6,6);
}
}
</SCRIPT>
</HEAD>
<BODY>
<DIV align=center>
<OBJECT id=wb height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
<INPUT onclick=javascript:printit() type=button value=打印 name=button_print />
<INPUT onclick=javascript:printsetup(); type=button value=打印頁面設(shè)置 name=button_setup />
<INPUT onclick=javascript:printpreview(); type=button value=打印預(yù)覽 name=button_show />
一按開始的減肥了卡時(shí)間段
</DIV>
</BODY>
</HTML>
3、jQuery實(shí)現(xiàn)(支持局部打?。?
<html>
<head>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script>
$(function(){
$("input#biuuu_button").click(function(){
$("div#myPrintArea").printArea();
});
</script>
</head>
<body>
<input id="biuuu_button" type="button" value="打印"></input>
<div id="myPrintArea">.....文本打印部分.....</div> <div class="quote_title">引用</div><div class="quote_div"></div>
</body>
</html>
1、js實(shí)現(xiàn)(可實(shí)現(xiàn)局部打?。?
復(fù)制代碼 代碼如下:
<html>
<title>js打印</title>
<head></head><body>
<input id="btnPrint" type="button" value="打印" onclick="javascript:window.print();" />
<input id="btnPrint" type="button" value="打印預(yù)覽" onclick=preview(1) />
<style type="text/css" media=print>
.noprint{display : none }
</style>
<p class="noprint">不需要打印的地方</p>
<script>
function preview(oper)
{
if (oper < 10)
{
bdhtml=window.document.body.innerHTML;//獲取當(dāng)前頁的html代碼
sprnstr="<!--startprint"+oper+"-->";//設(shè)置打印開始區(qū)域
eprnstr="<!--endprint"+oper+"-->";//設(shè)置打印結(jié)束區(qū)域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //從開始代碼向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//從結(jié)束代碼向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
</script>
<p>XXXXX</p>
<!--startprint1-->要打印的內(nèi)容<!--endprint1-->
</body>
</html>
2、調(diào)用windows底層打印,報(bào)安全警告,不建議使用(不支持局部打?。?
復(fù)制代碼 代碼如下:
<HTML>
<HEAD>
<TITLE>javascript打印-打印頁面設(shè)置-打印預(yù)覽代碼</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312" />
<SCRIPT language=javascript>
function printsetup(){
// 打印頁面設(shè)置
wb.execwb(8,1);
}
function printpreview(){
// 打印頁面預(yù)覽
wb.execwb(7,1);
}
function printit()
{
if (confirm('確定打印嗎?')) {
wb.execwb(6,6);
}
}
</SCRIPT>
</HEAD>
<BODY>
<DIV align=center>
<OBJECT id=wb height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
<INPUT onclick=javascript:printit() type=button value=打印 name=button_print />
<INPUT onclick=javascript:printsetup(); type=button value=打印頁面設(shè)置 name=button_setup />
<INPUT onclick=javascript:printpreview(); type=button value=打印預(yù)覽 name=button_show />
一按開始的減肥了卡時(shí)間段
</DIV>
</BODY>
</HTML>
3、jQuery實(shí)現(xiàn)(支持局部打?。?
復(fù)制代碼 代碼如下:
<html>
<head>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script>
$(function(){
$("input#biuuu_button").click(function(){
$("div#myPrintArea").printArea();
});
</script>
</head>
<body>
<input id="biuuu_button" type="button" value="打印"></input>
<div id="myPrintArea">.....文本打印部分.....</div> <div class="quote_title">引用</div><div class="quote_div"></div>
</body>
</html>
您可能感興趣的文章:
- JS實(shí)現(xiàn)頁面打印功能
- Javascript打印局部頁面實(shí)例
- js實(shí)現(xiàn)局部頁面打印預(yù)覽原理及示例代碼
- js調(diào)用iframe實(shí)現(xiàn)打印頁面內(nèi)容的方法
- 利用javascript實(shí)現(xiàn)web頁面中指定區(qū)域打印
- javascript打印大全(打印頁面設(shè)置/打印預(yù)覽代碼)
- js實(shí)現(xiàn)頁面打印功能實(shí)例代碼(附去頁眉頁腳功能代碼)
- javascript 局部頁面打印實(shí)現(xiàn)代碼
- 用javascript實(shí)現(xiàn)頁面打印的三種方法
- JS實(shí)現(xiàn)頁面打?。ㄕw、局部)
相關(guān)文章
JS實(shí)現(xiàn)圖片延遲加載并淡入淡出效果的簡單方法
我們大家都知道,對于一個(gè)網(wǎng)站最占用帶寬,最影響頁面顯示速度的東西就是圖片。圖片是很重要的,作為一個(gè)站長我們是千方百計(jì)的使用各種技巧來優(yōu)化圖片,但其實(shí)有一種簡單的方法,只需要幾行代碼就能達(dá)到這種效果。同時(shí)還附加一種淡入淡出的顯示效果,下面一起來看看。2016-08-08
JavaScript用JSONP跨域請求數(shù)據(jù)實(shí)例詳解
Javascript跨域訪問是web開發(fā)者經(jīng)常遇到的問題,什么是跨域,就是一個(gè)域上加載的腳本獲取或操作另一個(gè)域上的文檔屬性。下面這篇文章主要介紹了JavaScript用JSONP跨域請求數(shù)據(jù)的方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-01-01
Nest.js快速啟動(dòng)API項(xiàng)目過程詳解
這篇文章主要為大家介紹了Nest.js快速啟動(dòng)API項(xiàng)目過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
javascript如何判斷數(shù)組內(nèi)元素是否重復(fù)的方法集錦
javascript如何判斷數(shù)組內(nèi)元素是否重復(fù)的方法集錦...2007-02-02
前端常見的時(shí)間轉(zhuǎn)換方法以及獲取當(dāng)前時(shí)間方法小結(jié)
在做開發(fā)時(shí)會(huì)對不同的時(shí)間格式進(jìn)行轉(zhuǎn)換,下面這篇文章主要給大家介紹了關(guān)于前端常見的時(shí)間轉(zhuǎn)換方法以及獲取當(dāng)前時(shí)間方法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01
使用JavaScript實(shí)現(xiàn)彈出層效果的簡單實(shí)例
下面小編就為大家?guī)硪黄褂肑avaScript實(shí)現(xiàn)彈出層效果的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05

