我想用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>
答案 0 :(得分: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;
}
}