css代码行上的javascript unkown错误

时间:2015-11-02 08:33:43

标签: javascript jquery html css

我有这个html表:

<center><input type="button" value="Print last visit report" id="printpagebutton" onclick="printData()"/>
      <input type="button" value="Print all reports" id="printpagebutton2" onclick="printData1()"/>
    </center></BR>
<center></center>
<div class=WordSection1 id="mydiv1">
<?php while($rows = mysqli_fetch_array($result)) {  $data2 =$rows['echo_files'];
$dataFile2 = str_replace('/', '\\', $data2); ?>


<div id="mydiv">
  <form action="/clinic form/update/update.php" id="Form2" method="post">
<table border="1" align="center" id="table">
<tr align="center">
<th colspan="3" bgcolor="#7a7878">DR. Omar GHNEIM - Patient Medical History</th>
</tr>
<tr align="center">
<th colspan="3"><?php echo 'Medical History of '.$rows['name']?></th>
</tr>
  <tr>
    <th>Medicaments</th>
    <th>Illness</th>
    <th>Echo Results</th>
  </tr>
  <tr>
  <?php if(!empty($rows['remarcs']) && trim($rows['remarcs'])!=''):?>
    <td width="250px"><?php echo $rows['remarcs'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <?php if(!empty($rows['illness']) && trim($rows['illness'])!=''):?>
    <td width="250px"><?php echo $rows['illness'] ?></td>
        <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <?php if(!empty($rows['echo']) && trim($rows['echo'])!=''):?>
    <td width="250px"><?php echo $rows['echo'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
  </tr>
<tr>
    <th>Clinic Test Result</th>
<th>Habbits</th>
<th>Allergy</th>

  </tr>
  <tr>
    <?php if(!empty($rows['test_res']) && trim($rows['test_res'])!=''):?>
    <td width="250px"><?php echo $rows['test_res'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <?php if(!empty($rows['habbits']) && trim($rows['habbits'])!=''):?>
    <td width="250px"><?php echo $rows['habbits'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <?php if(!empty($rows['allergy']) && trim($rows['allergy'])!=''):?>
    <td width="250px"><?php echo $rows['allergy'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
  </tr>
  <tr>
    <th>Occupation</th>
<th>PMHx</th>
<th>PSHx</th>
  </tr>
  <tr>
    <?php if(!empty($rows['occup']) && trim($rows['occup'])!=''):?>
    <td width="250px"><?php echo $rows['occup'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <?php if(!empty($rows['pmhx']) && trim($rows['pmhx'])!=''):?>
    <td width="250px"><?php echo $rows['pmhx'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <?php if(!empty($rows['pshx']) && trim($rows['pshx'])!=''):?>
    <td width="250px"><?php echo $rows['pshx'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
</tr>
<tr>
<th colspan="3">Echo Files</th>
</tr>
<tr>
<?php if(!empty($data2) && trim($data2)!=''):?>
<td colspan="3" align="center"><center><a href='download_PopUp.php?data=<?php echo $dataFile2; ?>'>Echo Test files exist</a></center></td>
<?php else: ?>
<td colspan="3" align="center"><center>No echo files</center></td>
<?php endif;?>
</tr>
<tr>
<th>P.E</th>
<?php if(!empty($rows['pe']) && trim($rows['pe'])!=''):?>
    <td width="250px"><?php echo $rows['pe'] ?></td>
    <?php else: ?>
    <td width="250px" align="center">Not Available</td>
    <?php endif; ?>
    <th rowspan="4" align="left">Signature</th>
</tr>
<tr>
<th>Date</th><td><?php echo $rows['date'] ?></td>
</tr>
<tr>
<th>Address of Patient</th><td><?php echo $rows['address'] ?></td>
</tr>
<tr>
<th>Phone Number of patient</th><td><?php echo $rows['phone_num'] ?></td>
</tr>

</table>

这个javascript文件用css在页面中打印div,但是dreamweaver软件会出错:

 function printData()
{
   var divToPrint=document.getElementById("mydiv");
   newWin= window.open("");
   newWin.document.write(divToPrint.outerHTML);
    var css =`table, td, th {
        border: 1px solid black;
        text-align:justify;
    }

    th {
        background-color: #7a7878;
        text-align:center
    }`;
   var div = $("<div />", {
    html: '&shy;<style>' + css + '</style>'
  }).appendTo( newWin.document.body);
   newWin.print();

   newWin.close();
}

$('button').on('click',function(){
printData();
});

enter image description here

但是在我点击F12的浏览器中,没有给出任何错误,并且css样式不起作用。

2 个答案:

答案 0 :(得分:0)

IE中不支持

Template strings。这可能就是Dreamweaver在该行上抛出错误的原因。

要么换掉新行:

var myString = 'some \n\
multiline \n\
string';

或连接线:

var myString = 'some \n' +
    'multiline \n' +
    'string';

答案 1 :(得分:-1)

javascript中的多行字符串可以像大多数现代浏览器一样,但在IE和旧浏览器中不起作用。

你应该改变

var css =`table, td, th {
    border: 1px solid black;
    text-align:justify;
}

th {
    background-color: #7a7878;
    text-align:center
}`;

为:

var css = "table, td, th { \n\
    border: 1px solid black; \n\
    text-align:justify; \n\
} \n\
\n\
th {  \n\
    background-color: #7a7878; \n\
    text-align:center \n\
}";

制作它更好:

var css = "table, td, th { \n"+
"    border: 1px solid black; \n"+
"    txt-align:justify; \n"+
"} \n"+
"th {  \n"+
"    background-color: #7a7878; \n"+
"    text-align:center; \n"+
"}";

您的css未显示的原因是: 一旦IE处理了加载了页面的所有样式,添加另一个样式表的唯一可靠方法是使用document.createStyleSheet(url)

有关详细信息,请参阅createStyleSheet上的MSDN article

修改

因此,在您的情况下,您可以将上述css代码添加到table.css,并将其上传到您的服务器。目前你想要添加样式,你可以使用

document.createStyleSheet('http://yourserver.com/table.css');