如何使用php打印网页的某些部分?
我想打印一个网页。我已经为这项工作编写了代码。代码是:如何使用php打印网页的某些部分?,php,javascript,Php,Javascript,我想打印一个网页。我已经为这项工作编写了代码。代码是: function printPage(){ var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>'; var data = '<button onclick="window.print()">Print this page</
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();
};
函数printPage(){
var tableData=''+document.getElementsByTagName('table')[0].innerHTML+'';
变量数据='打印此页
'+表格数据;
myWindow=window.open('','',宽度=500,高度=600');
myWindow.innerWidth=screen.width;
myWindow.innerHeight=screen.height;
myWindow.screenX=0;
myWindow.screenY=0;
myWindow.document.write(数据);
myWindow.focus();
};
但是我不想在打印输出中使用“打印此页面”按钮。您可以使用@media css样式方法:
@media print {
/* css here to take out the "print this */
}
这将仅在打印时应用css样式
例如,您可以为按钮设置一个类,例如class=“printbtn”
然后:
@media print {
.printbtn { display: none; }
}
只需将css用于打印定义的区域,如
<style type="text/css">
#printit { display: block; }
@media print
{
#dont-printit { display: none; }
#printit { display: block; }
}
</style>
#printit{display:block;}
@媒体印刷品
{
#不打印它{显示:无;}
#printit{display:block;}
}
使用
打印web区域的一部分……最好使用样式表添加CSS,但是如果您必须根据您的问题使用javascript,只需添加以下内容:var CSS=myWindow.document.createElement('style');css.type=“text/css”;css.innerHTML=“@media print{button{display:none;}}”;myWindow.document.body.appendChild(css);