我使用以下插件以 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但没有得到它,所以我怎么能做到这一点。
最佳答案
由于您具有表格格式,因此可以使用 first-child
和 last-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();
这样您就不需要刷新页面。
关于javascript - 如何隐藏html2canvas中特定的dom元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31510248/