代码之家  ›  专栏  ›  技术社区  ›  Christopher Altman

jquery“this”关键字和选择器的基本筛选器

  •  5
  • Christopher Altman  · 技术社区  · 16 年前

    当使用' 'jquery中的关键字,添加基本筛选器的语法是什么?

    例如:

    $(this):contains('foo')
    
    $(this):visible OR $(this:visible)
    
    3 回复  |  直到 12 年前
        1
  •  6
  •   Starx    12 年前

    搜索此中的项目:

    $(':visible, any-selector', this)
    $(this).find(':visible, any-selector')
    

    如果您想要一个正确或错误的返回:

    if($(this).is(':visible, any-selector')){
        alert('this is visible, or matches "any-selector"');
        }
    else{
        alert('this is hidden, or doesn\'t match "any-selector"');
        }
    
        2
  •  3
  •   Philippe Leybaert    16 年前

    filter()方法的作用是:

    $(this).filter(":contains(foo)");
    $(this).filter(":visible")
    

    根据文件:

    从与指定表达式不匹配的匹配元素集中删除所有元素。

        3
  •  1
  •   duckyflip    16 年前

    使用此语法: jQuery( expression, [context] )

    $(":contains(foo)", this)
    $(":visible", this)
    $("any-selector", this)