引入依赖库
<!-- jQuery依赖 -->
<script type="text/javascript" src=".path/to/jquery/3.3.1/jquery.min.js"></script>
<!-- printThis依赖 -->
<script type="text/javascript" src=".path/to/printThis.js"></script>
HTML
<div class="demo">
<p>//TODO 要打印的内容</p>
<img id="kitty-one" alt="cute kitten" src="assets/images/cat1.jpg" />
<img class="u-pull-left" id="kitty-two" alt="cute kitten" src="assets/images/cat2.jpg"/>
<img class="u-pull-right" id="kitty-three" alt="cute kitten" src="assets/images/cat3.jpg"/>
<p>//TODO 更多打印的内容</p>
</div>
脚本初始化
$('.demo').printThis();
HTML
<div class="demo">
<p>//TODO 要打印的内容</p>
<img id="kitty-one" alt="cute kitten" src="assets/images/cat1.jpg" />
<img class="u-pull-left" id="kitty-two" alt="cute kitten" src="assets/images/cat2.jpg"/>
<img class="u-pull-right" id="kitty-three" alt="cute kitten" src="assets/images/cat3.jpg"/>
<p>//TODO 更多打印的内容</p>
</div>
脚本初始化
$('#kitty-one, #kitty-two, #kitty-three').printThis({
importCSS: false, //打印时不使用样式
header: "<h1>自定义打印标题!</h1>"
});
更多使用方法请参考官方文档:https://github.com/jasonday/printThis
the end