0

我想用css打印一个div。它在我申请时与我一起工作,inline css但在external and internal css它不起作用时。下面是我的代码,

<script src="jquery.jqprint.0.3.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function() {
  $("#PrintButton").click( function() {
      $('#divToPrint').jqprint();
      return false;
  });
});
</script>

<style type="text/css">
@media screen,print
  {
  .test {background:#0F0; width:500px; height:200px;}
  }
</style>

<input id="PrintButton" type="button" name="Print" value="Print" />

<div id="divToPrint" class="test">
Print Me, I'm in DIV
</div>
4

1 回答 1

3

我已经尝试过您的代码,它似乎可以与外部 CSS 一起正常工作。

<html>
<head>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery.jqprint-0.3.js" type="text/javascript"></script>
<link rel="stylesheet" href="test.css">

<script language="javascript" type="text/javascript">
$(function() {
  $("#PrintButton").click( function() {
      $('#divToPrint').jqprint();
      return false;
  });
});
</script>
</head>
<body>
<input id="PrintButton" type="button" name="Print" value="Print" />

<div id="divToPrint" class="test">
Print Me, I'm in DIV
</div>
<body>
</html>

和外部css文件名:test.css

@media screen,print
{
  .test {
            background:#0F0; width:500px; height:200px;
        }
}
于 2014-01-11T18:38:57.823 回答