php - 如何使用php打印网页的某些部分?

标签 php javascript

我想从网页中打印出来。我已经为此和这项工作编写了代码。代码是:

function printPage(){
        var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>';
        var data = '<button onclick="window.print()">Print this page</button><br/>'+tableData;       
        myWindow=window.open('','','width=500,height=600');
        myWindow.innerWidth = screen.width;
        myWindow.innerHeight = screen.height;
        myWindow.screenX = 0;
        myWindow.screenY = 0;
        myWindow.document.write(data);
        myWindow.focus();
    };

但我不想在打印输出中显示“打印此页”按钮。

最佳答案

您可以使用@media css样式方法:

@media print {
/* css here to take out the "print this */
}

这只会在您打印时应用 css 样式。

例如,您可以为按钮指定一个类,例如 class="printbtn"

然后:

@media print {

    .printbtn { display: none; }

}

关于php - 如何使用php打印网页的某些部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15803461/

相关文章:

php - codeigniter 指定限制为 NULL 在最新的 CI 版本 2.1.2 中不起作用

javascript - jQuery - 在文本区域中查找文本

javascript - 使用 JS 在文本中查找并突出显示单词

javascript - 与该页面内的 iframe 共享页面的全局 javascript 变量

javascript - IE11 是否使用哈希表来优化 document.getElementById()?

javascript - Rails/Angular JS : Ngclick not appearing to work

php - 查阅图像目录或数据库来统计有多少个更正确吗?

javascript - 在 PHP 中使用解析的移动重定向

php - 如何在 bootstrap 模式中显示 php 搜索结果? Modal 在显示结果后消失了?

php - 构建消息系统的最佳方法是什么