[英]Electron : How to print only a part of html (div) in electron silently?
[英]Print only certain part of the <div> content
我有以下JavaScript代碼來打印內容
<script type="text/javascript">
function Print(print)
{
Popup($(print).html());
}
function Popup(data)
{
var mywindow = window.open("", "print");
mywindow.document.write("<html><head><title>Report</title>");
mywindow.document.write("</head><body>");
mywindow.document.write("<div align='center'>");
mywindow.document.write(data);
mywindow.document.write("</div>");
mywindow.document.write("</body></html>");
mywindow.print();
mywindow.close();
return true; }
</script>
在我的HTML中,我有以下代碼:
<html>
<body>
<p><a href="javascript:Print('#print')">Print</a></p>
<div id="print">
<h1>Report</h1>
<table>
<tr><th>Date</th><th>Remarks</th><th>Amount</th><th>Actions</th></tr>
<tr>
<td>10/11/2014</td>
<td>Hello</td>
<td>$14</td>
<td>Edit</td>
</tr>
</table>
</div>
</body>
</html>
我只想打印前三列。 我不想打印第4欄“操作”。 當我嘗試使用上述代碼打印內容時,它會打印所有4列。 請在以下方面幫助我。
您可以使用jquery做到這一點。
$(document).ready(function(){
$('.tabel').find(':nth-child(4)').hide();
});
您可以簡單地將樣式顯示為不顯示該td的ID
HTML內部:
....
<th id="act">Actions</th>
....
<td id="act">Edit</td>
在JS內部:
mywindow.document.write("<html><head><style>#act{display:none;}</style><title>Report</title>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.