循环遍历列表并根据if语句隐藏子li


Looping through list and hide child li based on if statement

我有一个jquery移动站点,它有一个动态无序列表,由postgres和php中的while命令生成。

页面准备好后,我如何通过每个列表块和阅读文本,在 span class="status" ,如果它等于'D',然后隐藏相关的 class='edit_btn' 在弹出式菜单。

我收集这可以在jQuery中完成?

请看我的例子,这将有助于解释我的问题。http://jsfiddle.net/jamesil/wbcVy/1/

这是我到目前为止所做的,但我相信我走错了方向

$('ul.bookings li').each(function() {
$(this).each(function(i) {
    var status = $('span.status',this).text();
    if (status = 'D') 
        $('ul.bookings ul li.edit_btn').hide();
});

如果你修复了无效的html问题,你可以使用下面的jQuery来隐藏你的编辑按钮:

$('#bookings li').filter(function() {
    return $(this).find('span.status').text() == 'D';
}).find('div').each(function() {
    //this is the bit where you need to find the id from the comment inserted by mobile jquery
    var divId = '#' + this.innerHTML.replace(/[^0-9]+/g, '') + '-popup';
    $(divId).find('li.edit_btn').hide();
});

请注意,这将假设在您的li中只有一个div。你可能想给这个div一个类这样你就可以在find上做一个更好的选择器但我不确定移动版jQuery是否会删除这个类因为它似乎已经删除了原来的ID

如果你不能改变你的html结构,那么就把.find改为.next

示例