如何打印<div id =“frm”>

时间:2016-11-24 04:26:18

标签: javascript php

当我们只想打印div id =“frm”时如何修复代码。并且一旦点击按钮就隐藏页眉和页脚以及按钮打印(我的意思是在打印预览中应该只显示frm中的内容)

wstring myString;
//...
wcin >> myString;
//...
wcout << myString;
<html>
 <head>
  <title>Clinic System Management</title>
  <link rel='stylesheet' type='text/css' href='style2.css'/>
  <link rel='stylesheet' type='text/css' href='css/print.css' media='print'/>
 
 <script>
 function printdiv (divname) {
 	var printcontents = document.getElementById.innerHTML;
	var originalcontents = document.body.innerHTML;
	
	document.body.innerHTML = printcontents;
	
	window.print();
	
	document.body.innerHTML =originalcontents;
}
 </script>
 
 </head>

 <body>
 <div id="hiderow">
 <?php
 include ('./includess/header2.html');
 ?>
 </div>
   <div id="printOnly">
   <div id="frm">
         <center><h1>Medical Certificate</h1></center>

          To whom it may concern, </p>
          
          This is to certify that.....................[name of the patient] </p>

          of ................................................................</p>
          
          Was examined and treated at the ........................................ [your clinic name] </p>
                             
          on ..........................[date] with the followig diagnosis.</p>        
                                        
          .........................................................................................</p>
          
          .........................................................................................</p>
          
          And would need medical attention for .......................... days barring complication.</p>
          <br/>
          
                                                ...................  </p>
                                                Doctor(s) Signature  </p>
</div>   
</div>       
<input type="button" onclick="printdiv('printOnly')" value="Print Here"/>     
</body>
</html>                                                 
<?php
include ('./includes/footer.html');
?>

1 个答案:

答案 0 :(得分:0)

您应该在getElementById部分中使用表单的ID,如下所示,然后打印它,这是一个有效的代码片段,

<html>
 <head>
  <title>Clinic System Management</title>
  <link rel='stylesheet' type='text/css' href='style2.css'/>
  <link rel='stylesheet' type='text/css' href='css/print.css' media='print'/>
 <style>
 #printOnly
{
	display: inline;
}

#hiderow
{
	.no-print, .no-print*
	{
	
	display: none ! important;
}
</style>
<script>
 function printdiv (divname) {
 	var printcontents = document.getElementById("frm").innerHTML;
	var originalcontents = document.body.innerHTML;
	
	document.body.innerHTML = printcontents;
	
	window.print();
	
	document.body.innerHTML =originalcontents;
}
 </script>
 
 </head>

 <body>
 <div id="hiderow">
 </div>
   <div id="printOnly">
   <div id="frm">
         <center><h1>Medical Certificate</h1></center>

          To whom it may concern, </p>
          
          This is to certify that.....................[name of the patient] </p>

          of ................................................................</p>
          
          Was examined and treated at the ........................................ [your clinic name] </p>
                             
          on ..........................[date] with the followig diagnosis.</p>        
                                        
          .........................................................................................</p>
          
          .........................................................................................</p>
          
          And would need medical attention for .......................... days barring complication.</p>
          <br/>
          
                                                ...................  </p>
                                                Doctor(s) Signature  </p>
</div>   
</div>       
<input type="button" onclick="printdiv('printOnly')" value="Print Here"/>     
</body>
</html>