1 回答
TA贡献1852条经验 获得超7个赞
querySelectorAll改为使用,并仅选择<span>带有tracklist_track_title, 的标签span.tracklist_track_title:
const trackList = Array.from(
document.querySelectorAll('span.tracklist_track_title'),
span => span.textContent
);
console.log(trackList);
<table>
<tr class=" tracklist_track track" data-track-position="8">
<td class="tracklist_track_pos">8</td>
<td class="track tracklist_track_title ">
<span class="tracklist_track_title">Shapeshifting</span>
<blockquote><span class="tracklist_extra_artist_span">Vocals – <a href="/artist/764815-Rachel-Dreyer">Rachel Dreyer</a></span></blockquote>
</td>
<td width="25" class="tracklist_track_duration">
<span>6:02</span>
</td>
</tr>
<tr class=" tracklist_track track" data-track-position="9">
<td class="tracklist_track_pos">9</td>
<td class="track tracklist_track_title ">
<span class="tracklist_track_title">Rose</span>
<blockquote><span class="tracklist_extra_artist_span">Vocals – <a href="/artist/764814-Silke-Roch">Silke Roch</a></span></blockquote>
</td>
<td width="25" class="tracklist_track_duration">
<span>5:49</span>
</td>
</tr>
</table>
选择器字符串比getElementsBy方法更强大和灵活。
span.tracklist_track_title意思是:选择标签名span也有类名的元素tracklist_track_title。
添加回答
举报