Home >Web Front-end >JS Tutorial >jQuery method to control web page printing specified area_jquery

jQuery method to control web page printing specified area_jquery

WBOY
WBOYOriginal
2016-05-16 16:05:161172browse

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.

Statement:
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