通过JQuery打印DIV内容

通过JQuery打印DIV内容

本文介绍了通过JQuery打印DIV内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的页面中有很多div,但是我想使用jquery打印特定div的内容.我发现有一个插件.

suppose i have many div's in my page but i want to print the content of specific div using jquery. i found there is a plugin for that.

jQuery打印元素

使用此插件,我们可以轻松打印div内容,如下所示.

using this plugin we can easily print div content like below.

$('SelectorToPrint').printElement();

但是如果我的div隐藏在页面中会发生什么.这样就行了.这个插件可以打印隐藏的div的内容吗?

but what happen if my div is hidden in page. so then does it work. this plugin can print the content of hidden div?

如果打印机未与客户端计算机连接,会发生什么情况.我是否想向客户显示找不到打印机"的消息?如何处理这种情况.因此,请告诉我什么是在页面中打印隐藏的div内容以及在未连接打印机的情况下处理打印机问题的最佳方法.

what happen if printer is not attach with client machine. i want to show message if printer is not there to customer that "Printer not found"? how to handle this situation. so please advise me what would be the best approach to print the content of hidden div in page and as well as handle printer issue if printer is not attached.

谢谢

推荐答案

您的问题听起来好像您自己也没有尝试过,所以我什至不希望回答,但是:如果一个隐藏的div不能印有那一行:

your question doesn't sound as if you even tried it yourself, so i shouldn't even think of answering, but: if a hidden div can't be printed with that one line:

$('SelectorToPrint').printElement();

只需将其更改为:

$('SelectorToPrint').show().printElement();

应该可以在所有情况下正常工作.

which should make it work in all cases.

对于其他,没有解决方案.插件将为您打开打印对话框,用户必须在其中选择打印机.您根本无法确定打印机是否附有javascript(并且您(几乎)无法在没有打印对话框的情况下进行打印-如果您正在考虑这样做的话).

for the rest, there's no solution. the plugin will open the print-dialog for you where the user has to choose his printer. you simply can't find out if a printer is attached with javascript (and you (almost) can't print without print-dialog - if you're thinking about that).

注意:

这篇关于通过JQuery打印DIV内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 20:02