这是我的代码。我想在使用处方按钮中打印病人的处方详细信息。我的问题是处方按钮不起作用。函数不起作用。
<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>发布于 2015-05-13 16:14:32
你已经写了这一行:
mywindow.document.write('<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.css"
type="text/css" />');在两行中(字符串包含换行符)。这会使JavaScript无效,因此不会创建您的函数。
去掉换行符,它就可以工作了。
https://stackoverflow.com/questions/30208808
复制相似问题