如何使用打印按钮只从html页面打印一个div内容 [英] How to print only one div content from html page using print button
本文介绍了如何使用打印按钮只从html页面打印一个div内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的html代码中有2个div标签,我有一个打印按钮在页面顶部。当我点击打印按钮,它给我的一切打印我有在html页面来自两个div的内容)。我想限制此打印按钮的功能,直到第一个div,我将在下一个div之前添加另一个打印按钮,独立打印该div内容。有什么办法可以做到吗?
I have 2 div tags in my html code.and I have 1 print button on the top of the page.when I click on the print button , it is giving me everything in the print what I have on html page(means content from both the divs). I want to restrict this print button's functionality till 1st div only and I will add another print button before next div to print that div content independently. Is there any way I can do this?
<html>
<body>
<input type="button" value="Print" class="noprint" onclick="window.print();return false;">
<div>
...
//my content.Want to print only this div when I will click print button.
...
</div>
//I will add another print button here which will allow me to print the next div.
<div>
...
//my content
...
</div>
</body>
</html>
推荐答案
@media print {
*
{
display: none !important;
}
.printable
{
display: block !important;
}
}
然后将可打印类添加到您想要的div打印。
Then add the printable class to your div you want to print.
这篇关于如何使用打印按钮只从html页面打印一个div内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文