我需要使用选择器来获取CSS格式不佳的网页的HTML内容。
如何通过“我需要此处”获取文字内容?
<tbody>
<tr class="nth">
<td class="title">Address</td>
<td>I need this here</td>
</tr>
</tbody>
有人可以提供一些线索吗?
使用这个我得到了“地址”:
$('tbody tr.nth td').html()
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以使用.eq()
将匹配元素集合减少到指定索引处的元素。
$('tbody tr.nth td').eq(1).html()
OR
$('tbody tr.nth td.title').next('td').html()
答案 2 :(得分:1)
您可以使用:last
选择器选择 last 匹配的TD:
document.write($('tbody tr.nth td:last').html())
&#13;
<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>
&#13;
答案 3 :(得分:1)
尝试
$(".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>