jQuery的另一个页面打印插件,允许用户打印网页的特定元素,同时保留页面样式(甚至额外的CSS)和输入/表单值。
# NPM $ npm install print-this # Bower $ bower install print-this
1.将jQuery库和jQuery打印这个插件的脚本放在关闭的body标记之前:
<script src="//code.jquery.com/jquery.min.js"></script> <script src="printThis.js"></script>
2.附加功能打印此
在任何要打印的元素上。
$('form,h1,p').printThis();
3.自定义打印插件的可能选项。
$('SELECTORS').printThis({ // shows debug info debug: false, // import page CSS importCSS: true, // import styles importStyle: false, // print outer container printContainer: true, // additonal CSS file loadCSS: "", // page title pageTitle: "", // remove inline styles removeInline: false, // custom selectors to filter inline styles. removeInline must be true removeInlineSelector: "body *", // print delay in ms printDelay: 333, // header header: null, // footer footer: null, // preserve input/form values formValues: true, // preserve the base tag (if available) base: false, // copy canvas elements (experimental) canvas: false, // html doctype doctypeString: '<!DOCTYPE html>', // remove script tags before appending removeScripts: false, // copy classes from the html & body tag copyTagClasses: false, // copy styles from html & body tag (for CSS Variables) copyTagStyles: false, });
4.提供回调功能。
$('SELECTORS').printThis({ // callback function for printEvent in iframe beforePrintEvent: null, // function called before iframe is filled beforePrint: null, // function called before iframe is removed afterPrint: null });
v2.0.0版本(2022-06-04)
v1.16.0 (2022-05-30)
v1.15.1 (2019-08-05)
v1.14.1 (2018-11-04)
v1.14.0 (2018-07-16)
2018-01-11
2017-12-18
2017-10-30
2017-08-02
2017-04-10
2017-03-07
2017-01-17
2017-01-17
2016-12-15