【问题标题】:Jquery .filter() QuestionJquery .filter() 问题
【发布时间】:2010-04-08 15:28:23
【问题描述】:

给定以下 HTML:

<div class="parent">
<span class="child">10</span>
</div>

<div class="parent">
<span class="child">20</span>
</div>

我想根据它的跨度值(子值)过滤和隐藏父 div,所以想到了做类似的事情:

<script>
$('span.child').filter(function(index) {
 return ($(this).text() < '15');
}).$(this).parent().hide();
</script>

没有成功...我没有根据跨度值隐藏父 div..

谁能帮帮我?

非常感谢。

【问题讨论】:

    标签: jquery filter


    【解决方案1】:

    试试这个:

    jQuery('span.child').filter(function(index) {
       return (jQuery(this).text() < '15');  
    }).parent().hide();
    

    【讨论】:

      【解决方案2】:

      只需删除最后一个$(this),如下所示:

      $('span.child').filter(function(index) {
        return $(this).text() < '15';
      }).parent().hide();
      

      .filter() 返回过滤后的元素集,它采用您选择的内容,过滤掉您想要删除的内容,然后您继续链接结果。 You can see this working here.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-17
        • 2012-02-25
        • 2012-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多