假设我的页面中有很多 div,但我想使用 jquery 打印特定 div 的内容。我发现有一个插件。
使用这个插件我们可以很容易的打印出如下的div内容。
$('SelectorToPrint').printElement();
但是如果我的 div 隐藏在页面中会发生什么。那么它是否有效。这个插件可以打印隐藏div的内容吗?
如果打印机没有连接到客户端机器会发生什么。如果打印机不在客户那里,我想显示消息“找不到打印机”?如何处理这种情况。所以请告诉我什么是打印页面中隐藏 div 内容的最佳方法,以及如果未连接打印机则如何处理打印机问题。
谢谢
最佳答案
我更喜欢这个,我已经测试过它并且可以正常工作
https://github.com/jasonday/printThis
$("#mySelector").printThis();
或
$("#mySelector").printThis({
* debug: false, * show the iframe for debugging
* importCSS: true, * import page CSS
* printContainer: true, * grab outer container as well as the contents of the selector
* loadCSS: "path/to/my.css", * path to additional css file
* pageTitle: "", * add title to print page
* removeInline: false * remove all inline styles from print elements
* });
关于javascript - 通过 JQuery 打印 DIV 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7530192/