如何向网页添加打印按钮 [英] How to add a print button to a web page

查看:347
本文介绍了如何向网页添加打印按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站(以PHP编码)的一个页面上,我想添加2(甚至更多)打印按钮,每个按钮打印一部分网页。例如,在一个页面上有一个表,其下有一些值和2个图形。我想添加2个打印按钮,一个按钮打印表,另一个打印两个图形。我发现此示例,但无法清楚地了解。任何帮助或示例都会帮助我。

On one of my pages in my website(coded in php), i'm trying to add 2 (even more) print buttons each one printing a portion of the webpage. For example, on a page there is a table with some values and 2 graphs underneath it. I would like to add 2 print buttons, one button printing the table and the other one printing both the graphs. I've found this Example but could not understand clearly. Any help or examples would help me.

提前感谢。

推荐答案

p>一个简单的想法是创建一些以前的css打印规则ad hoc,例如

A simple idea is to create some previous css printing rules ad hoc, e.g.

.printtable * { display : none; }
.printtable table { display : block; }

.printtableandgraph * { display : none; }
.printtableandgraph img { display : block; }

那么这两个按钮应该添加一个 .printtable window.print()之前的body元素(或包含您的表和图形的其他元素)的 .printtableandgraph c $ c>语句

then the two buttons should add a .printtable and a .printtableandgraph class for the body element (or other element containing your table and graphs) just before window.print() statement

(如果用户在同一打印按钮上点击两次或更多次,则先检查元素是否已设置该类名称)

(if user click twice or more on the same print button check previously if the element has already set that class name)

这篇关于如何向网页添加打印按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆