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

jQuery method to control web page printing specified area_jquery

WBOY
Release: 2016-05-16 16:05:16
Original
1147 people have browsed it

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>
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!