V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kstsca

如何取到触发焦点外部的元素数据。。路过看看,谢谢

  •  
  •   kstsca · Jun 21, 2014 · 3886 views
    This topic created in 4331 days ago, the information mentioned may be changed or developed.




    譬如如何取到“文章”这个数据,注意是点击span text后。
    8 replies    2014-06-22 19:37:59 +08:00
    switch
        1
    switch  
       Jun 21, 2014
    先匹配到 ul.submenu 再查找到 .submenu-header:
    $this.closest("ul.submenu").children("li.submenu-header").text();
    kstsca
        2
    kstsca  
    OP
       Jun 21, 2014
    @switch 但你无法定位哪一个。。Tables呢,这个有多个这个元素。。需要用到this
    paloalto
        3
    paloalto  
       Jun 21, 2014
    $ul.on('click', 'span.text', function (e) {

    })
    paloalto
        4
    paloalto  
       Jun 21, 2014
    @kstsca 1楼 给出的 $this.clesest('ul.submenu') 就是离 this 最近的那个 ul . 可以定位到的。

    而且可以直接匹配 id 啊,ul#form 是唯一的嘛。

    可以不用 this 的:
    $ul.on('click', 'span.text', function (e) {
    var text = $('ul#form .submenu-header').text();
    $('.page-header-section .semibold').text(text);
    })
    kstsca
        5
    kstsca  
    OP
       Jun 21, 2014
    @paloalto 那#tables呢
    paloalto
        6
    paloalto  
       Jun 21, 2014
    @kstsca 哦 还想用在 #tables 上啊 那就用1楼同学的写法吧。:P
    kstsca
        7
    kstsca  
    OP
       Jun 21, 2014
    @paloalto 也不行。。必须用到this,但又不好获取到外面节点数据。
    liyandong
        8
    liyandong  
       Jun 22, 2014
    找父亲的文章儿子
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2669 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:26 · PVG 21:26 · LAX 06:26 · JFK 09:26
    ♥ Do have faith in what you're doing.