代码之家  ›  专栏  ›  技术社区  ›  Gennady Shumakher

jquery v1.3.2按属性查找元素

  •  27
  • Gennady Shumakher  · 技术社区  · 17 年前

    我需要找到并迭代所有具有特定属性的子元素。以下代码在jquery 1.2.6中运行良好,但在1.3.2中抛出了异常

    $(parentElement).find('*[@someAttributeName]').each(function(index){
        doSomething(this);
    });
    

    5 回复  |  直到 14 年前
        1
  •  40
  •   Joseph Silber    14 年前

    我相信,只要去掉@就行了。

    $(parentElement).find('[someAttributeName]').each(function(index){
        doSomething(this);
    });
    

    selector 文档:

    注意:在jQuery 1.3[@attr]样式中 选择器被删除(它们是 以前在jQuery 1.2中已弃用)。 只需将“@”符号从您的 选择器,使其工作 再一次。

        2
  •  2
  •   Konstantin Tarkus    17 年前

    $(parentElement).find('*[someAttributeName]').each(function(index){
        doSomething(this);
    });
    

        3
  •  2
  •   Nakilon earlonrails    14 年前

    [@attribute] @

        4
  •  1
  •   Yuseferi    14 年前

       $('.youritem').each(function(){
                              if($(this).attr('title') == 'add image')
                                               $(this).attr('id','imageuploader');
    
                            });
    
        5
  •  0
  •   Community Mohan Dere    9 年前

    required="" .

    当我切换到 required="required" 。也许其他组合也有效 https://stackoverflow.com/a/3012975/588759