Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何向网页添加打印按钮_Php_Css - Fatal编程技术网

Php 如何向网页添加打印按钮

Php 如何向网页添加打印按钮,php,css,Php,Css,在我网站的一个页面上(用php编码),我试图添加2个(甚至更多)打印按钮,每个按钮打印一部分网页。例如,在一个页面上有一个表,下面有一些值和两个图形。我想添加两个打印按钮,一个按钮打印表格,另一个按钮打印两个图形。我发现了这一点,但无法理解清楚。任何帮助或例子都会帮助我 提前感谢。这是html/javascript代码,单击后将启动浏览器的打印对话框 <button onClick="window.print()">Print this page</button> 打印

在我网站的一个页面上(用php编码),我试图添加2个(甚至更多)打印按钮,每个按钮打印一部分网页。例如,在一个页面上有一个表,下面有一些值和两个图形。我想添加两个打印按钮,一个按钮打印表格,另一个按钮打印两个图形。我发现了这一点,但无法理解清楚。任何帮助或例子都会帮助我


提前感谢。

这是html/javascript代码,单击后将启动浏览器的打印对话框

<button onClick="window.print()">Print this page</button>
打印此页

一个简单的想法是创建一些以前的css打印规则,例如

.printtable * { display : none; }
.printtable table { display : block; }

然后,这两个按钮应该为body元素(或包含表格和图形的其他元素)在
window.print()之前添加
.printtable
.printtableandgraph


(如果用户在同一打印按钮上单击两次或两次以上,请事先检查元素是否已设置该类名)

如果您的表位于id为div中,请使用:

<a href="#null" onclick="printContent('printTable')">Click to print table</a>

编辑:这里是函数“printContent()”


打印按钮

<button onClick="window.print()">Print this page</button>`
打印此页`

使用此代码打印任何网页只有一个缩回按钮和菜单栏。要打印页面的一部分,可以使用print.css和print按钮进行快速简单的操作

  • 设置print.css文件并包括:
  • body{可见性:隐藏;}
    
    .print{visibility:visible;}
    仅此代码就可以打印整个页面。。。它不能用来选择打印页面的哪一部分。@Ed Manet是的,我知道window.print()函数。但是它没有选择网页的一部分。我认为任何浏览器都不能只打印页面的一部分。它将打印您在页面上显示的任何内容。因此,请打开一个包含要打印内容的新窗口,或隐藏所有不想打印的内容。在调用window.print之前,请尝试设置不同的
    @media
    打印样式,具体取决于单击的按钮。@Piskvor,更简单的是:只需创建一些以前的规则并切换类名:)@F.Calderan:或其他。同样的道理,原则上:)真棒的解决方案!我唯一需要添加的是包含CSS表以保持格式化。(
    newwin.document.write(“”)
    )这个答案和一个有什么不同?
    <script type="text/javascript">
    <!--
    function printContent(id){
    str=document.getElementById(id).innerHTML
    newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
    newwin.document.write('<HTML>\n<HEAD>\n')
    newwin.document.write('<TITLE>Print Page</TITLE>\n')
    newwin.document.write('<script>\n')
    newwin.document.write('function chkstate(){\n')
    newwin.document.write('if(document.readyState=="complete"){\n')
    newwin.document.write('window.close()\n')
    newwin.document.write('}\n')
    newwin.document.write('else{\n')
    newwin.document.write('setTimeout("chkstate()",2000)\n')
    newwin.document.write('}\n')
    newwin.document.write('}\n')
    newwin.document.write('function print_win(){\n')
    newwin.document.write('window.print();\n')
    newwin.document.write('chkstate();\n')
    newwin.document.write('}\n')
    newwin.document.write('<\/script>\n')
    newwin.document.write('</HEAD>\n')
    newwin.document.write('<BODY onload="print_win()">\n')
    newwin.document.write(str)
    newwin.document.write('</BODY>\n')
    newwin.document.write('</HTML>\n')
    newwin.document.close()
    }
    //-->
    </script>
    
    <button onClick="window.print()">Print this page</button>`