jquery - 将 .find 的目标从 tr:has(th) 更改为查找 div
问题描述
我正在使用(http://bl.ocks.org/kalebdf/ee7a5e7f44416b2116c0)中的代码将html表下载到csv。我用过其他人,但他们不能在 IE 上工作。上面链接中的那个确实适用于 IE。
我遇到的问题是我的表格是使用 div 中的列标题生成的 - 列标题
当我下载表格 ot csv 时,表格行数据包含在 csv 中,但缺少列标题。
我假设原因是因为它们在 div 中。js 文件的一部分为标题和行创建了一个变量。
var $headers = $table.find('tr:has(th)'),
$rows = $table.find('tr:has(td)')
我的问题是:如何更改 tr:has(th) 以便在 div 中找到文本?
解决方案
假设标题div
在th
...
喜欢:
<tr>
<th>
<div>blah</div>
</th>
<th>
<div>blah-blah</div>
</th>
</tr>
尝试将grabRow
功能更改为:
function grabRow(i,row){
var $row = $(row);
//for some reason $cols = $row.find('td') || $row.find('th') won't work...
var $cols = $row.find('td');
if(!$cols.length) $cols = $row.find('div'); // Change th for div on this line
return $cols.map(grabCol)
.get().join(tmpColDelim);
}
推荐阅读
- scala - 可选分页
- python - 如果语句问题打印所有短语
- cuckoo - 没有pip2怎么下载
- mysql - 如何根据具有特定值的字段逐行递增 id
- list - 从 Firestore Flutter 中读取子集合
- javascript - React.memo 不适用于功能组件。如果我所看到的不支持该功能,那么优化的另一种方法是什么?
- python - OpenCV Python:如何将图像叠加到另一个图像的中心
- c# - Asp.net core 3.0 在发布或构建时发布视图文件 (.cshtml)
- sql - 这段代码是什么意思..[select @a:=password(?)]
- javascript - 如何在从另一个页面加载的模式中运行脚本?