找找文档,应该是 this.parentNode.previousSibling
但是返回的不是对象而是 text...
怎么获取父节点的上一兄弟节点呢
找找文档,应该是 this.parentNode.previousSibling
但是返回的不是对象而是 text...
怎么获取父节点的上一兄弟节点呢
|
1
0
|
|
2
previousElementSibling 而不是 previousSibling
|
|
3
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. |
|
RoycomJan 28, 2016
5
mark
|
|
6
@just1
对于不支持 previousElementSibling 的浏览器。循环获取 previousSibling ,直到其 nodeType 为 1 |
|
westpskJan 28, 2016
7
我只想问为什么要用裴博士作为头像
|