在网页下载特定的table的对应处理

来源:互联网 发布:java math.random用法 编辑:程序博客网 时间:2024/06/06 12:45

在javaweb开发过程中,可能会需要让页面实现进行下载的更能,而且是下载特定的table或者其他,剩下的页面的其他东西就不需要了。

今天我就简单说一下。

1、在页面创建一个button 

<input type="button" id="tablePrint"  value="打印"/>
2、在js文件中写对应的处理函数

$("#tablePrint").click(function () {    })
点击打印按钮实现打印功能。但是我们知道利用window.print();这个函数是实现的打印整个页面,当然这就包括网页上面的所有的东西。
但是根据我们的需要往往只需要下载某个东西,比如说只需要一个table,其他的控件什么的都不需要。
那么就可以让其他控件的idName.style.display='none';
<div style="margin-top:2%;" id="headshow">
 。。。。。
</div>
headshow.style.display = 'none';
但是我们很多时候在打印完之后,会回到之前打印的那一页,但是会发现,隐藏的控件就直接是隐藏了的。
最后别忘了让隐藏的控件进行显示
headshow.style.display = 'block';
所以总的来说js文件如下所示:
$("#tablePrint").click(function () {    alert("您确定要打印吗?");    headshow.style.display = 'none';    window.print();    headshow.style.display = 'block';});
这么效果就出来了,希望能给大家帮助。



原创粉丝点击