Home > Web Front-end > JS Tutorial > body text

JS partial printing method

小云云
Release: 2017-11-28 09:33:57
Original
2581 people have browsed it

In this article, we share with you a very simple technology. JS implements partial printing. There are many kinds of web printing, so there are also many methods of JS printing. Now we will teach you a method of JS implementing partial printing.

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>局部打印案例</title> 
<script type="text/javascript">   
  function doPrint() {   
    bdhtml=window.document.body.innerHTML;   
    sprnstr="<!--startprint-->";   
    eprnstr="<!--endprint-->";   
    prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);   
    prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));   
    window.document.body.innerHTML=prnhtml;  
    window.print();   
}   
</script> 
</head> 
   
<body> 
<p>1不需要打印的地方</p> 
<p>2这里不要打印啊</p> 
<!--startprint--><!--注意要加上html里star和end的这两个标记--> 
<h1>打印标题</h1> 
<p>打印内容~~</p> 
<!--endprint--> 
<button type="button" onclick="doPrint()">打印</button> 
<p>不打印的地方啊哈哈哈哈</p> 
<p>2</p> 
</body> 
</html>
Copy after login

The above content is a case of JS implementing partial printing. I hope it can help everyone.

Related recommendations:

js control web printing (partial printing) method arrangement_javascript skills

js or jquery can realize page printing Partial printing_javascript skills

Several methods of printing results

The above is the detailed content of JS partial printing method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template