找找文档,应该是 this.parentNode.previousSibling
但是返回的不是对象而是 text...
怎么获取父节点的上一兄弟节点呢
1
just1 OP 0
|
2
Keita1314 2016-01-28 21:12:31 +08:00 1
previousElementSibling 而不是 previousSibling
|
3
Keita1314 2016-01-28 21:16:52 +08:00 1
Notes
Gecko-based browsers insert text nodes into a document to represent whitespace in the source markup. Therefore a node obtained, for example, using Node.firstChild or Node.previousSibling may refer to a whitespace text node rather than the actual element the author intended to get. See Whitespace in the DOM and W3C DOM 3 FAQ: Why are some Text nodes empty? for more information. |
5
Roycom 2016-01-28 22:09:37 +08:00
mark
|
6
pysama 2016-01-28 22:34:56 +08:00 1
@just1
对于不支持 previousElementSibling 的浏览器。循环获取 previousSibling ,直到其 nodeType 为 1 |
7
westpsk 2016-01-28 22:38:12 +08:00
我只想问为什么要用裴博士作为头像
|