【问题标题】:Filter with jquery用 jquery 过滤
【发布时间】:2016-07-13 11:28:46
【问题描述】:

我想用jquery做过滤,首先我隐藏所有div标签然后尝试只显示选定的div标签,我在一个变量中选择它们并检查收集的div的长度是否正确但不能循环显示它们.

 var filter = $('.sec5row.'+classtype); //this is the selected variable
 //I try to loop it and show 
 for (var i = 0; i < = filter.length; i++){
      $(filter[i]).show();
 }


 but then I do filter[1].show() it works

请告诉我正确的循环方式。

【问题讨论】:

    标签: jquery html loops


    【解决方案1】:

    你根本不需要循环:

    $('.sec5row.' + classtype).show();
    

    jQuery objects are collections。当您调用诸如show 之类的方法时,它会应用于对象中包含的所有元素。

    【讨论】:

      【解决方案2】:

      您不需要为了显示它们而遍历元素:

       $('.sec5row.'+classtype).show();
      

      【讨论】:

        【解决方案3】:

        使用这个:

            $('.sec5row.'+classtype).each(function(this){
        
        //do whatever you want to do in this loop, filtering, display, checking properties etc..$(this) will give you the element selector
        $(this).show();
        
            });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-10-25
          • 2015-06-19
          • 2018-03-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多