如何在硬拷贝上删除打印按钮



我尝试这样做以隐藏我的硬拷贝上的按钮,但仍显示在我的硬拷贝

<script type="text/javascript">
var button = document.getElementById('print') button.addEventListener('click',hideshow,false);
function printFrom_hidden()
{
    document.getElementById('print').style.display="block";
    //document.getElementById('').style.display = ;
    this.style="display:none";
}
</script>
<input type="button" value="Print" name="print" id="print" onClick="printFrom();printFrom_hidden();">

我建议为此目的使用媒体类型用于CSS样式表吗?请参阅http://coding.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/

为打印机编写样式表远远优于黑客对屏幕样式的更改,以使其适合打印机。出于您的目的,它应该像将其添加到样式表

一样简单
@media print {
    input#print { display: none }
}

我的理解是要完成的方式。可悲的是,网络开发人员和设计师都经常忘记并非所有内容都是屏幕!

您正在调用printform();首先,然后printfrom_hidden()。因此,在打印完成后,隐藏了打印按钮。因此,它们会倒数。

<input type="button" value="Print" name="print" id="print" onClick="printFrom_hidden();printFrom();">

yourpage.php或yourpage.html或yourpage.aspx或任何

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
  <head>
    <meta http-equiv='content-type' content='text/html;charset=utf-8' />
    <style type='text/css'>
      @import 'common.css'; @import `yourpage.css';
    </style>
  </head>
<body class='njs'>
  <input type='button' value='Print' name='print' id='print' />
  <script type='text/javascript src='common.js'></script>
  <script type='text/javascript src='yourpage.js'></script>
</body>
</html>

common.js

//<![CDATA[
var doc = document, bod = doc.body, IE = parseFloat(navigator.appVersion.split('MSIE')[1]);
bod.className = 'js';
function gteIE(version, className){
  if(IE >= version)bod.className = className;
}
function E(e){
  return doc.getElementById(e);
}
//]]>

yourpage.js

//<![CDATA[
E('print').onclick = function(){
  print();
}
//]]>

当然,使用Dan Farrell建议的CSS。

yourpage.css

#print{
  /* print button CSS when not in print mode */
}
@media print{
  /* CSS for this page goes in here */
  body{
    /* body CSS here */
  }
  #print{
    /* print button CSS here */
  }
}

最新更新