我是 jquery 新手。可能我的查询看起来有些愚蠢,但实际上我不明白如何实现下面的事情。
无论如何,这是我的查询:
我有一些动态表如下:
<table id='example1'>
<thead>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
</thead>
</table>
<table id='example2'>
<thead>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
</thead>
</table>
我正在尝试如下:
$($('table').attr('id') ' thead th').each( function () {
}
上面好像有问题,有人可以纠正吗?
我需要实现如下:
$( dynamicTableId thead th).each(function () {
}
最佳答案
如果您尝试迭代所有第 th
元素,则无需使用,只需使用表作为选择器即可。您还可以使用 has 属性选择器来确保它有一个 id
$('table[id] thead th').each( function () {
})
关于javascript - jquery动态表id选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29795888/