簡體   English   中英

如何在html2canvas中隱藏特定的dom元素?

[英]How to hide specific dom element in html2canvas?

我使用以下插件以PNG格式導出表格數據,

<li><a href="#" onClick ="$('#datawtable').tableExport({type:'excel',escape:'false', ignoreColumn:[0, 4]});"> <img src='icons/xls.png' width='24px'> XLS</a></li>
<li><a href="#" onClick ="$('#datawtable').tableExport({type:'doc',escape:'false', ignoreColumn:[0, 4]});"> <img src='icons/word.png' width='24px'> Word</a></li>
<li><a href="#" onClick ="$('#datawtable').tableExport({type:'png',escape:'false'});"> <img src='icons/png.png' width='24px'> PNG</a></li>

<script type="text/javascript" src="js/tableExport.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/html2canvas.js"></script>

這樣的輸出, 在此處輸入圖片說明 在這里,我想隱藏我檢查過此https://github.com/niklasvh/html2canvas/issues/126的 “照片”和“選項”列,但沒有得到它,我該怎么做。

由於采用表格格式,因此可以使用firs-childlast-child來訪問表的第一列和最后一列。

$("#tableID th:first-child, #tableID th:last-child, #tableID td:first-child, #tableID td:last-child").hide();

要么

$("#tableID tr th:first-child, #tableID tr th:last-child, #tableID tr td:first-child, #tableID tr td:last-child").hide();

使用html2canvas渲染之前,您需要隱藏元素。

在html2canvas渲染之后,您需要使用show()函數顯示隱藏的td。 所以它就像:

 $("#tableID th:first-child, #tableID th:last-child, #tableID td:first-child, #tableID td:last-child").show();

要么

 $("#tableID tr th:first-child, #tableID tr th:last-child, #tableID tr td:first-child, #tableID tr td:last-child").show();

因此,您無需刷新頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM