javascript - 如何隐藏html2canvas中特定的dom元素?

标签 javascript jquery export

我使用以下插件以 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>

输出是这样的, enter image description here 在这里我想隐藏“照片”和“选项”列我检查了这个https://github.com/niklasvh/html2canvas/issues/126但没有得到它,所以我怎么能做到这一点。

最佳答案

由于您具有表格格式,因此可以使用 first-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();

这样您就不需要刷新页面。

关于javascript - 如何隐藏html2canvas中特定的dom元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31510248/

相关文章:

javascript - 丰富的 Web 应用程序的嵌套链接(标签)的有效替代方案?

javascript - Form_Open 始终提交 - 通过 Ajax 提交 - CodeIgniter

jquery:用跨度替换输入

c# - 在 ASP.NET 中将 HTML 内容写入 Word 文档时出现问题

linux - 如何将文件列表传递给 linux zip 命令

import - 如何将财务数据保存到mathematica文件中?

javascript - TVML 创建动态模板

javascript - 未使用 javascript 设置 Samesite cookie 属性

javascript - 使用 moment.js 动态更改倒计时值

javascript - jquery droppable 不工作