Js打印
2020-12-13 02:18
标签:des style blog class code java Js打印,搜素材,soscw.com Js打印 标签:des style blog class code java 原文地址:http://www.cnblogs.com/shcolo/p/3716442.htmldoctype html>
html lang="en">
head>
meta charset="UTF-8">
meta name="Generator" content="EditPlus?">
meta name="Author" content="">
meta name="Keywords" content="">
meta name="Description" content="">
title>Documenttitle>
head>
body>
script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js">
script>
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="";//设置打印开始区域
eprnstr="";//设置打印结束区域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
prnhtmlprnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
script>
p>要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容要打印的内容p>
body>
html>