File tree Expand file tree Collapse file tree
2-ui/1-document/03-dom-navigation
3-navigation-links-which-null Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 这里有很多方法,比方说 :
1+ 这里有很多种方法,例如 :
22
33
44获取 ` <div> ` DOM 节点:
55
66``` js
77document .body .firstElementChild
8- // 或者
8+ // 或
99document .body .children [0 ]
10- // 或者 (第一个节点是空格,所有我们拿第二个 )
10+ // 或 (第一个节点是空格,所以我们应该获取的是第二个 )
1111document .body .childNodes [1 ]
1212```
1313
1414获取 ` <ul> ` DOM 节点:
1515
1616``` js
1717document .body .lastElementChild
18- // 或者
18+ // 或
1919document .body .children [1 ]
2020```
2121
22- 获取第二个 ` <li> ` (即包含 Pete 的节点)
22+ 获取第二个 ` <li> ` (即包含 Pete 的节点):
2323
2424``` js
25- // 获取 <ul>, 然后拿它的最后一个子元素
25+ // 获取 <ul>,然后获取它的最后一个子元素
2626document .body .lastElementChild .lastElementChild
2727```
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ importance: 5
1818</html >
1919```
2020
21- 如何能访问到以下内容 :
21+ 对于以下各项,请给出至少一种访问方式 :
2222- ` <div> ` DOM 节点?
23- - ` <ul> ` DOM 节点?
23+ - ` <ul> ` DOM 节点?
2424- 第二个 ` <li> ` 节点(即包含 Pete 的节点)?
Original file line number Diff line number Diff line change 1- 1 . 是的,这是真的。` elem.lastChild ` 一直是最后一个元素,它就没有 ` nextSibling ` ,所有如果存在子节点,这个问题的答案就是正确 。
2- 2 . 不,这是错的,因为 ` elem.children[0] ` 是元素中的第一个子元素。但是或许有非元素的节点在它之前 。所以 ` previousSibling ` 或许是一个文本节点 。
1+ 1 . 是的,这是真的。` elem.lastChild ` 就是最后一个元素,它没有 ` nextSibling ` 。
2+ 2 . 不,这是错的,因为 ` elem.children[0] ` 是元素中的第一个子元素。但是在它前面可能存在非元素的节点 。所以 ` previousSibling ` 可能是一个文本节点 。
33
4- 请注意,对于这两种情况,如果没有子节点就会出现错误。比如说如果 ` elem.lastChild ` 是 ` null ` ,我们就访问不到 ` elem.lastChild.nextSibling ` 。
4+ 请注意,对于这两种情况,如果没有子节点,那么就会报错。
5+
6+ 如果这里没有子节点,那么 ` elem.lastChild ` 是 ` null ` ,所以我们就访问不到 ` elem.lastChild.nextSibling ` 。并且 ` elem.children ` 是空的(像一个空数组一样 ` [] ` )。
Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ importance: 5
66
77如果 ` elem ` 是任意一个 DOM 元素节点……
88
9- - ` elem.lastChild.nextSibling ` 值一直都是 ` null ` 这个判定是不是真的?
10- - ` elem.children[0].previousSibling ` 值一直都是 ` null ` 这个判定是不是真的?
9+ - ` elem.lastChild.nextSibling ` 值一直都是 ` null ` , 这个判定是不是真的?
10+ - ` elem.children[0].previousSibling ` 值一直都是 ` null ` , 这个判定是不是真的?
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ importance: 5
22
33---
44
5- # 选择所有对角线单元格
5+ # 选择所有对角单元格
66
77编写代码来把表中的对角单元格都绘制成红色。
88
9- 你需要用代码从 ` <table> ` 中获取到所有的对角线 ` <td> ` ,然后绘制它们:
9+ 你需要用代码从 ` <table> ` 中获取所有的对角单元格 ` <td> ` ,然后绘制它们:
1010
1111``` js
1212// td 表示的是对单元格的引用
You can’t perform that action at this time.
0 commit comments