[英]not able to add the css file to html while print
我正在尝试在打印时将css文件添加到HTML内容。 但是没有添加css文件。 我得到的输出没有CSS。 谁能帮帮我吗...
这是我的代码
<html> <head> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> <script type="text/javascript"> function PrintElem(elem) { Popup($(elem).html()); } function Popup(data) { var mywindow = window.open('', 'mydiv', 'height=700,width=1200'); mywindow.document.write('<html><head><title></title>'); mywindow.document.write('<link rel="stylesheet" href="print.css" type="text/css" media="print"/>'); mywindow.document.write('</head><body >'); mywindow.document.write(data); mywindow.document.write('</body></html>'); mywindow.document.close(); // necessary for IE >= 10 mywindow.focus(); // necessary for IE >= 10 mywindow.print(); mywindow.close(); return true; } </script> </head> <body> <div id="mydiv"> This will be printed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a quam at nibh adipiscing interdum. Nulla vitae accumsan ante. </div> <div> This will not be printed. </div> <div id="anotherdiv"> Nor will this. </div> <input type="button" value="Print Div" onclick="PrintElem('#mydiv')" /> </body> </html>
这是我的CSS文件“ print.css”
@media print { #mydiv { border: 10px solid !important; color: red; font-size:20px !important; } }
找出问题所在:
解决方案,请将整个div而不是仅将div.html()传递到Popup函数中
尝试类似的方法或尝试其他方法
function PrintElem(elem)
{
Popup($(elem)); // send div not html only
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.