推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
just1

如何获取父节点的上一兄弟节点

  •  
  •   just1 · Jan 28, 2016 · 3207 views
    This topic created in 3783 days ago, the information mentioned may be changed or developed.

    找找文档,应该是 this.parentNode.previousSibling
    但是返回的不是对象而是 text...
    怎么获取父节点的上一兄弟节点呢

    8 replies    2016-01-29 23:24:20 +08:00
    just1
        1
    just1  
    OP
       Jan 28, 2016
    0
    Keita1314
        2
    Keita1314  
       Jan 28, 2016   ❤️ 1
    previousElementSibling 而不是 previousSibling
    Keita1314
        3
    Keita1314  
       Jan 28, 2016   ❤️ 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.
    just1
        4
    just1  
    OP
       Jan 28, 2016
    @Keita1314 非常感谢
    Roycom
        5
    Roycom  
       Jan 28, 2016
    mark
    pysama
        6
    pysama  
       Jan 28, 2016   ❤️ 1
    @just1
    对于不支持 previousElementSibling 的浏览器。循环获取 previousSibling ,直到其 nodeType 为 1
    westpsk
        7
    westpsk  
       Jan 28, 2016
    我只想问为什么要用裴博士作为头像
    just1
        8
    just1  
    OP
       Jan 29, 2016 via Android
    @westpsk 当初要传头像,刚好这张图片
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3203 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 68ms · UTC 12:42 · PVG 20:42 · LAX 05:42 · JFK 08:42
    ♥ Do have faith in what you're doing.