我需要使用一个选择器来获取一个糟糕的CSS格式网页的HTML内容。
如何获取带有"我需要这个"的文本内容?
<tbody>
<tr class="nth">
<td class="title">Address</td>
<td>I need this here</td>
</tr>
</tbody>
有人能提供一些线索吗?
使用这个我得到了"地址":
$('tbody tr.nth td').html()
这将有助于找到第二个<td>
子级。
$('tbody tr.nth td:eq(1)').html()
参考::eq()选择器
您可以使用.eq()
将匹配的元素集减少到指定索引处的元素集。
$('tbody tr.nth td').eq(1).html()
或
$('tbody tr.nth td.title').next('td').html()
您可以使用:last
选择器来选择最后一个匹配的TD:
document.write($('tbody tr.nth td:last').html())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody>
<tr class="nth">
<td class="title">Address</td>
<td>I need this here</td>
</tr>
</tbody>
</table>
<hr>
尝试
$(".nth :not(.title)").html();
console.log($(".nth :not(.title)").html())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js">
</script>
<table>
<tbody>
<tr class="nth">
<td class="title">Address</td>
<td>I need this here</td>
</tr>
</tbody>
</table>