gpt4 book ai didi

jquery - 循环遍历表行

转载 作者:行者123 更新时间:2023-12-01 07:14:45 25 4
gpt4 key购买 nike

我想循环遍历表行,但总是出现错误(无法识别的表达式)。调用each函数时出现错误。

我该如何解决这个问题?

提前致谢

这是我的代码:

jQuery

$("#searchValue").keyup(function() {

var table = $(this).siblings('table').not(':hidden');
$(table +" tr").each(function() {

});
});

HTML

<table id='tablePlanning' class='tablesorter'>
<thead>
<tr>
<th>PR Code</th>
<th>Klant</th>
<th>Description</th>
<th>Project status</th>
<th>Project Leader</th>
<th>Coordinator</th>
<th>Account manager</th>
<th>Billing</th>
<th>Start Datum</th>
<th>Hardware</th>
</tr>
</thead>
<tbody>

</tbody>
</table>

<table id='tableProject' class='tablesorter'>
<thead>
<tr>
<th>Project ID</th>
<th>Description</th>
<th>Customer</th>
<th>Status</th>
<th>Max Hours</th>
<th>Achieved</th>
<th>Difference</th>
</tr>
</thead>
<tbody>

</tbody>
</table>

最佳答案

$(table +"tr") 将获取 table 引用的 jQuery 对象,将其转换为字符串 ("[object Object]"),将 "tr" 附加到它,然后尝试使用生成的字符串 "[object Object] tr" 作为选择器。

您可能想要find ,这是 jQuery 对象上可用的函数,用于搜索该 jQuery 对象中的元素内的后代元素:

table.find('tr').each(/*...*/);

关于jquery - 循环遍历表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com