我的 html 代码中有 2 个 div 标签。页面顶部有 1 个打印按钮。当我单击打印按钮时,它会打印 html 页面上的所有内容(意味着来自两个 div 的内容)。我想限制此打印按钮的功能,直到仅第一个 div,并且我将在下一个 div 之前添加另一个打印按钮以独立打印该 div 内容。有什么办法可以做到这一点吗?
<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 中。
关于html - 如何使用打印按钮从html页面仅打印一个div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26667390/