jQuery只返回过滤结果中的文本 [英] jquery return only text from filtered results

查看:140
本文介绍了jQuery只返回过滤结果中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经过过滤的html给了我

my html filtered is giving me

$.get(myURL, function(data) {
            $(data).find("td.Chats").filter(':gt(5)').appendTo('#regions');
        }, 'html')

结果:

<td class="Chats">Item 1</td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats">Item 2</td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats">Item 3</td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats"></td>
<td class="Chats"></td> 

我如何只获取带有文本的元素?或每5个?

How would I just get the elements with text? or every 5th ?

推荐答案

您可以使用.filter()方法:

$(data).find("td.Chats").filter(function(){
    return this.innerHTML !== '';
});

.not()方法:

$(data).find("td.Chats").not(':empty');

如果要排除第一个元素:

If you want to exclude the first element:

$(data).find("td.Chats").not(':empty').not(':first');

这篇关于jQuery只返回过滤结果中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆