代码之家  ›  专栏  ›  技术社区  ›  Barrie Reader

实时点击并瞄准jquery中的特定元素

  •  2
  • Barrie Reader  · 技术社区  · 14 年前

    我有以下代码:

    $("li.item").live('click',function() {
        $('#menu').animate({
    
        }, 500);
    });
    

    现在,我想将角色移动到您单击的li.item,但我不能使用 $(this) 因为那样会得到 #menu 项目。

    我也不能用 li.item 因为页面上有60个。有没有可能拉具体的 列项 我点击进入 animate 功能?

    2 回复  |  直到 14 年前
        1
  •  2
  •   Ben Everard    14 年前
    $("li.item").live('click',function() {
        // set the current li element to the li_item var
        var li_item = $(this);
        $('#menu').animate({
            // now we can use it in any way we choose
            li_item.addClass('hello');
        }, 500);
    });
    

    尝试一下:

        2
  •  0
  •   Sarfraz    14 年前

    但我不能像那样用美元 获取菜单项。

    它会得到点击的项目( li.item #menu ( ("li.item").live('click',function() { )

    有没有可能拉具体的 li.我点击进入动画的项目 功能?

    使用 $(this) :

    $("li.item").live('click',function() {
        $(this).animate({
        }, 500);
    });