代码之家  ›  专栏  ›  技术社区  ›  dungey_140

使用嵌套的$(this)语句时获取.text()值

  •  0
  • dungey_140  · 技术社区  · 6 年前

    当单击 <a> 标记,我想获取所述链接的文本值并将其放在另一个链接的内部 <div> ( .current-selection )在父级中。但是,我也需要 fadeOut() 家长允许这种变化在不可见的情况下发生,然后再将其带回来 fadeIn() . 我可以让它单独工作,但在fadeout()函数中放置文本更改时不行。

    下面的代码获取父级的文本,而不是最初单击的标记。像这样筑巢时我能做些什么呢?

    谢谢您。

    $('.filter').on( 'click', 'a', function() {
        // Fadeout text to allow for hidden text change
        $(this).parent.fadeOut(function() {
    
            // Change text of the current selection to match the item just clicked (not working)
            $('.filter').find('.current-selection').text($(this).text());   
    
        }).fadeIn();
    });
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Richi Zee    6 年前

    将文本放入额外变量

    $('.filter').on( 'click', 'a', function() {
        var value = $(this).html();
        $(this).parent().fadeOut(function() {
            $('.filter .current-selection').text(value);   
    
        }).fadeIn();
    });
    
    推荐文章