我正在尝试通过属性选择表中的一个单元格(可以使用querySelector(“ [data-name]”),但是我希望它仅返回第三列中的元素。是否可以合并一个nth-of-type(2)进行属性搜索?
我尝试使用querySelector(“ [数据名称]:nth-of-type(2)”],但这不起作用。
对于第3列,请尝试使用nth-of-type(3)
:nth-of-type()是一个CSS选择器,第一个孩子的索引将是1
http://www.w3schools.com/cssref/sel_nth-of-type.asp
console.log(document.querySelector("table tr [data-name]:nth-of-type(3)"));
<table>
<tr>
<td data-name="1">1</td>
<td data-name="2">2</td>
<td data-name="3">3</td>
<tr>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句