js或jquery實現(xiàn)頁面打印可局部打印
更新時間:2014年03月27日 15:38:57 作者:
這篇文章主要介紹了js或jquery如何實現(xiàn)頁面打印也可局部打印,需要的朋友可以參考下
js或jquery實現(xiàn)頁面打印(局部打印)
1、js實現(xiàn)(可實現(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="打印預覽" 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;//獲取當前頁的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底層打印,報安全警告,不建議使用(不支持局部打?。?
<HTML>
<HEAD>
<TITLE>javascript打印-打印頁面設(shè)置-打印預覽代碼</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312" />
<SCRIPT language=javascript>
function printsetup(){
// 打印頁面設(shè)置
wb.execwb(8,1);
}
function printpreview(){
// 打印頁面預覽
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=打印預覽 name=button_show />
一按開始的減肥了卡時間段
</DIV>
</BODY>
</HTML>
3、jQuery實現(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實現(xiàn)(可實現(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="打印預覽" 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;//獲取當前頁的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底層打印,報安全警告,不建議使用(不支持局部打?。?
復制代碼 代碼如下:
<HTML>
<HEAD>
<TITLE>javascript打印-打印頁面設(shè)置-打印預覽代碼</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312" />
<SCRIPT language=javascript>
function printsetup(){
// 打印頁面設(shè)置
wb.execwb(8,1);
}
function printpreview(){
// 打印頁面預覽
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=打印預覽 name=button_show />
一按開始的減肥了卡時間段
</DIV>
</BODY>
</HTML>
3、jQuery實現(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>
相關(guān)文章
Js 利用正則表達式和replace函數(shù)獲取string中所有被匹配到的文本(推薦)
這篇文章主要介紹了Js 利用正則表達式和replace函數(shù)獲取string中所有被匹配到的文本,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2018-10-10Web前端框架bootstrap實戰(zhàn)【第一次接觸使用】
Bootstrap是Twitter推出的一個開源的前端框架。這篇文章主要介紹了Web前端框架bootstrap實戰(zhàn),需要的朋友可以參考下2016-12-12JavaScript面試開發(fā)常用的知識點總結(jié)
這篇文章主要為大家詳細總結(jié)了JavaScript面試開發(fā)常用的知識點,感興趣的小伙伴們可以參考一下2016-08-08JS實現(xiàn)兼容火狐及IE iframe onload屬性的遮罩層隱藏及顯示效果
這篇文章主要介紹了JS實現(xiàn)兼容火狐及IE iframe onload屬性的遮罩層隱藏及顯示效果,涉及javascript事件響應(yīng)及針對頁面元素屬性的動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-08-08