• 请不要在回答技术问题时复制粘贴 AI 生成的内容
WhyAreYouSoSad
V2EX  ›  程序员

前端选择器有没有能实现这个需求的?

  •  
  •   WhyAreYouSoSad · Oct 28, 2016 · 2967 views
    This topic created in 3658 days ago, the information mentioned may be changed or developed.

    因为我是用 jq ,所以我拿 jq 举例,现在的元素选择器都是从上到下获取元素,但是现在我需要从下往上找元素,比如包含 width:5 的 textbox 的 div 。这个要怎么找?

    10 replies  •  2016-10-29 23:43:56 +08:00
    int64ago
    int64ago
    Oct 28, 2016❤️1
    1
    都 2016 年了,已经没人用 jQuery 了,都用 React 了!

    PS :你的问题, parent(s) 方法
    WhyAreYouSoSad
    WhyAreYouSoSad
    OP
    Oct 28, 2016
    2
    @int64ago 嗯,太羞耻了这个问题。让它沉吧
    meszyouh
    meszyouh
    Oct 28, 2016 via Android
    3
    没有父元素选择器,你上面说得那个例子,用 js 来遍历就可以了
    for8ever
    for8ever
    Oct 28, 2016
    4
    用 jq 可以的
    chaegumi
    chaegumi
    Oct 28, 2016
    5
    先$.find 到 textbox ,然后再 parent div
    weizhiyao008
    weizhiyao008
    Oct 28, 2016❤️1
    6
    $("div").has("input.textbox[width='5']") 这样?
    Pastsong
    Pastsong
    Oct 28, 2016❤️1
    7
    CSS4 有 :has() 选择器, 但现在还没有浏览器实现这个 http://caniuse.com/#feat=css-has
    aldenchang
    aldenchang
    Oct 28, 2016
    8
    用 6 楼的方法应该可以, has()返回 bool ,所以还是要获取到 div 集合,然后遍历筛选
    hkongm
    hkongm
    Oct 28, 2016
    9
    注意看,楼主 width:5 是冒号,肯定是 CSS ,不是 width=5
    所以属性选择器不行
    $(this).closest('div.textbox').each 里面写判断吧,不是单独选择器能完成的
    hasbug
    hasbug
    Oct 29, 2016
    10
    扯什么鬼 css4 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1320 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 21:48 · PVG 05:48 · LAX 13:48 · JFK 16:48
    ♥ Do have faith in what you're doing.