[英]JavaScript querySelectorAll
我正在研究的教程包含以下代碼和以下注釋。 我不明白
i)評論,特別是為什么它說“所有第二個表格單元格”。 “第二”是什么意思? 這不是正確的英語
ii)當說td + td
時,它到底在尋找什么? 該程序是關於從表中獲取數據的,因此,例如td + td
是否會在html表標簽<td></td>
之間選擇任何內容?
//use querySelector to find all second table cells
var cells = document.querySelectorAll("td + td");
它僅在<td>
之前尋找另一個<td>
( http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors )。
因此,使用此HTML,它將匹配<td>
的2-4(包括):
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
此處的示例: http : //jsfiddle.net/tMrbA/
如果你有一個選擇foo + bar
,它會搜索元素foo
,然后選擇匹配的所有元素bar
這是未來后姐弟foo
和具有相同的父為foo
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.