Home >Web Front-end >JS Tutorial >jQuery method to control web page printing specified area_jquery
The example in this article describes how jQuery controls the printing of a specified area on a web page. Share it with everyone for your reference. The specific analysis is as follows:
Use jQuery to control the web page to print a specified area. You can specify the id of a div area to print part of the web page, as shown in the following code:
<html> <head> <title>jquery 打印指定区域内容</title> <script src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript"> function printHtml(html) { var bodyHtml = document.body.innerHTML; document.body.innerHTML = html; window.print(); document.body.innerHTML = bodyHtml; } function onprint() { var html = $("#printArea").html(); printHtml(html); } </script> </head> <body> <div> <div id="printArea" style="width: 500px; text-align: left;"> 打印区域~~~~ </div> <br /> <div> <input type="button" id="btnPrint" onclick="onprint()" value="print" /> </div> </div> </body> </html>
I hope this article will be helpful to everyone’s jQuery programming.