最近工作中需要做到打印功能,爲了簡單起見就直接使用插件調用瀏覽器的打印功能。然後發現jquery.PrintArea.js這個插件蠻好用的。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文檔標題</title>
<script src="./js/jquery-2.1.0.js"></script>
<script src="./js/jquery.PrintArea.js"></script>
<style>
#print,#printno{margin-top:20px}
</style>
</head>
<body>
<div id="print">打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容打印的內容</div>
<div id="printno">
不打印的內容不打印的內容不打印的內容不打印的內容不打印的內容不打印的內容不打印的內容不打印的內容不打印的內容不打印的內容
</div>
<script>
$("#print").printArea();
</script>
</body>
</html>
這樣就可以直接選擇需要打印的區域,簡單好用。