我無法讓我的樣式表應用到我的彈出窗口。我可能錯過了簡單的東西,但我似乎無法弄清楚什麼。我使用相同鏈接的其他頁面上的CSS,它工作正常。在p將CSS應用到彈出窗口
CSS
.Code128 {
font-size: 50px;
}
JQuery的
$(document).ready(function() {
$('#Print').on("click", function() {
Popup($('#PrintDiv').html());
});
function Popup(data) {
var mywindow = window.open('', 'Print Label', 'height=400,width=600');
mywindow.document.write('<html><head><title>Print Label</title>');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="~/Content/Fonts.css"/>');
mywindow.document.write('<link rel="stylesheet" type="text/css" href="~/Content/Label.css"/>');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
// mywindow.print();
// mywindow.close();
}
});
HTML
<div id="PrintDiv">
<div class="Code128">BarCode</div>
<div class="Code128">Bar Code</div>
</div>
發佈您的CSS或沒有人能夠提供幫助。 – Nicolas 2014-09-26 20:42:23
在執行javascript之前是不是將CSS加載到DOM中? – 2014-09-26 20:43:05
爲什麼不直接將CSS導入添加到HTML頁面的頂部,而是將它們附加到頁面上。因爲如果Liam是正確的,這個代碼將永遠不會工作。另外,爲什麼在你的世界中,你的html,head和body標籤附加到你的彈出窗口而不是頁面上? – Nicolas 2014-09-26 20:45:43