js或jquery实现页面打印可局部打印
2017-01-12 08:55
796 查看
js或jquery实现页面打印(局部打印)
1、js实现(可实现局部打印)
代码如下:
[html] view
plain copy
print?
<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+"-->";//设置打印开始区域
eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
</script>
<p>XXXXX</p>
<!--startprint1-->要打印的内容<!--endprint1-->
</body>
</html>
2、jQuery实现(支持局部打印)
代码如下:
[html] view
plain copy
print?
<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实现(可实现局部打印)
代码如下:
[html] view
plain copy
print?
<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+"-->";//设置打印开始区域
eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
</script>
<p>XXXXX</p>
<!--startprint1-->要打印的内容<!--endprint1-->
</body>
</html>
2、jQuery实现(支持局部打印)
代码如下:
[html] view
plain copy
print?
<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或jquery实现页面打印可局部打印
- js或jquery实现页面打印可局部打印
- js或jquery实现页面打印(局部打印)
- js或jquery实现页面打印可局部打印
- js或jquery实现页面打印可局部打印
- js或jquery实现页面打印(局部打印)
- jquery.PrintArea.js 实现打印局部页面
- js或jquery实现页面打印可局部打印
- js实现局部页面打印预览原理及示例代码
- JS/Jquery_实现打印页面指定div的方法_个人总结
- JS 实现简单的页面局部打印例子
- JS实现页面打印(整体、局部)
- js 实现用window.print()打印页面中的部分内容,局部打印
- JS 实现简单的页面局部打印
- 利用css和js实现firefox和IE都支持的页面局部打印
- 实现页面打印(JS 、JQuery)
- js实现局部页面打印预览原理及示例代码
- jquery/js 实现 标签 条码 一维码 Web页面 区域打印解决方案 实例
- js或jquery实现页面打印
- 原生js实现的局部页面打印功能,可以适用vue和jq