我想获取tbody
中嵌套值的值。这是一个说明我的意思的示例。
在示例中,我想获取存储在 href
中的所有值。
<table id="toc" class="plainlinks" style="text-align: center" align="center">
<tbody>
<tr>
<td><b>Index</b></td>
</tr>
<tr>
<td>
<p>
<a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&from=A">A</a>
- <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&from=Ab">Ab</a>
- <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&from=Ad">Ad</a>
- <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&from=Ag">Ag</a>
- <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&from=Al">Al</a>
- <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&from=Ap">Ap</a>
- <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig--naamwoordsvorm_in_het_Nederlands&from=Ap1">Ap1</a>
</p>
</td>
</tr>
</tbody>
</table>
我尝试了以下语句来捕获值:
$('table tr').each(function (index, value) {
$('td' ,this).each(function (index, value) {
$('p', this).each(function (index, value) {
$('a',this).each(function (index, value) {
console.info($(this).html())
});
});
});
});
最佳答案
$('table tbody a').each(function(i,el){
console.info($(el).attr('href'));
})
将取“tbody”中的所有“a”
关于javascript - jQuery 如何捕获 tbody 中的嵌套值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41296367/