我用這 http://www.bennadel.com/blog/1591-ask-ben-print-part-of-a-web-page-with-jquery.htm打印格在Chrome中工作,不採取風格爲紐帶
使用這個jQuery打印一個div,但它不是在鉻工作,也需要它的風格是inernal在同一頁面中,不能使用外部CSS。
<html>
<head>
// code
<link rel="stylesheet" rel="stylesheet" media="screen" href="style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootssstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="jquery.print.js.js"></script>
<script>
$(document).ready(function(){
// Hook up the print link.
$("#print_div").click(function(){
alert("asd");
// Print the DIV.
$(".printable").print();
// Cancel click event.
return(false);
});
});
</script>
<head>
<body>
// code
<div class="container text-center">
<a href="#" class="btn btn-primary btn-lg print" id="print_div" >Print</a>
</div>
<div class="printable">
// section that need to be printed
// images, css form
// code
</div>
<body>
</html>
什麼更好的建議任何方式,我們可以整合這 https://github.com/jasonday/printThis
if (opt.importCSS) $("link[rel=stylesheet]").each(function() {
var href = $(this).attr("href");
if (href) {
var media = $(this).attr("media") || "all";
$doc.find("head").append("<link type='text/css' rel='stylesheet' href='" + href + "' media='" + media + "'>")
}
});
如果可能,可以描述_「需要樣式在同一頁面中,並且不能使用導入的CSS。」_?鏈接元素的'href'的url是什麼? ''.printable''div'應用哪個特定'style'?請注意,'.printable'類不會出現在OP的'html'內? – guest271314 2014-10-29 16:19:23