这是我的代码。我想用处方按钮打印患者处方细节。我的问题是处方按钮不起作用。该功能无效。
<div id="prescription_print">
table width="100%" border="0">
<tr>
<TD align="left" valign="top">
<?php foreach ($patient_info as $row2){ ?>
<?php echo 'Patient Name: '.$row2['name']; ?><br>
<?php echo 'Age: '.$row2['age']; ?><br>
<?php echo 'Sex: '.$row2['sex']; ?><br>
<?php } ?>
</td>
<td align="right" valign="top">
<?php $name = $this->db->get_where('doctor' , array('doctor_id' => $row['doctor_id'] ))->row()->name;
echo 'Doctor Name: '.$name;?><br>
<?php echo 'Date: '.date("d M, Y", $row['timestamp']); ?><br>
<?php echo 'Time: '.date("H:i", $row['timestamp']); ?><br>
</td>
</tr>
</table>
</div>
<!----------- prescription button------>
<a onClick="PrintElem('#prescription_print')" class="btn btn-primary btn-icon icon-left hidden-print">
Print Prescription
<i class="entypo-doc-text"></i>
</a>
<?php endforeach; ?>
<!----------- prescription function------>
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'prescription', 'height=400,width=600');
mywindow.document.write('<html><head><title>Prescription</title>');
mywindow.document.write('<link rel="stylesheet" href="assets/css/neon-theme.css" type="text/css" />');
mywindow.document.write('<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.css"
type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
return true;
}
</script>
答案 0 :(得分:0)
你写过这一行:
mywindow.document.write('<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.css"
type="text/css" />');
两行(字符串包含换行符)。这会使JavaScript无效,因此您的功能无法创建。
删除换行符并且有效。