2016-03-15 49 views
1

我试图根据他们的zip代码显示/隐藏商店列表。 数据通过WP加载到WP网站上,我试图创建一个脚本,我可以根据用户选择的区域隐藏/显示商店。 为此,我需要在例如商店之间显示邮编。 8000和9000, 而所有其他商店都隐藏。jQuery - 删除表格行,如果任何单元格包含X和Y之间的值

我试过这个,但无济于事。

$("#prices td").each(function() { 
    if ($(this).val() >= 8000 && $(this).val() <= 9000){ 
     $(this).parent().hide(); 
}; 

Here's a picture of the table

这里的桌子后面PHP的剪断(编辑,以减少大小)

<tbody> 
<?php foreach($results as $result){ ?> 
<tr data-id="<?php echo esc_attr($result->feed_id) ?>"> 
    <td> 
     <?php echo wp_get_attachment_image($result->store_logo, 'full') ?> 
    </td> 
    <td class="price"> 
     <?php echo compare_format_currency_number($result->price) ?> 
    </td> 
    <td> 
     <?php echo $result->store_zipcode ?> 
    </td> 
     <?php endif; ?>        
</tr> 
<?php }?> 
</tbody> 

目前,唯一有两家店铺,但更多的将被添加,而且我需要能够根据选定的邮编范围来显示/隐藏它们,这些邮编范围是按钮中预定义的。

有关如何在显示/隐藏行时顺利创建过渡时的建议,请务必注意。

谢谢。

+0

我想看到的table.But的HTML看着你的代码,我会告诉你用'$(本).find(“您的拉链柱”)的文本。 ()'和'$(this).closest()。hide() –

+0

编辑它以包含一些标记。 –

回答

1

这似乎为我工作的罚款: https://jsfiddle.net/y3llowjack3t/aj7rfk0m/

HTML:

<table> 
    <tr> 
     <td><input id="prices0" /></td> 
    </tr> 
    <tr> 
     <td><input id="prices1" /></td> 
    </tr> 
    <tr> 
     <td><input id="prices2" value="8001"/></td> 
    </tr> 
    <tr> 
     <td><input id="prices3" /></td> 
    </tr> 
</table> 

JQuery的:

$("input[id^=prices]").each(function() { 
    if ($(this).val() >= 8000 && $(this).val() <= 9000){ 
     $(this).parent().hide(); 
    } 
}); 

另一种方式,如果你不使用的输入: https://jsfiddle.net/y3llowjack3t/aj7rfk0m/1/

$("td[id^=prices]").each(function() { 
    if (parseInt($(this).text()) >= 8000 && parseInt($(this).text())<= 9000) { 
     $(this).parent().hide(); 
    } 
}); 

或:

$("td[id^=prices]").each(function() { 
    if ($(this).text() >= 8000 && $(this).text() <= 9000){ 
     $(this).parent().hide(); 
     } 
}); 
+0

我看到.val属性可能是错误的,因为邮政编码只是​​中的文本,而不是输入字段的值。 –

+0

@DanielPaaske是的,使用文本,​​没有val()属性。 $(“td [id^= prices]”)。each(function(){if(this).text()> = 8000 && $(this).text()<= 9000){这个).parent()。hide(); \t \t} }); – Blindsyde

+0

谢谢。它仍然不会工作。我的目标是​​错? #prices id是td之上的8个div,但所有到td的级别都有泛型类。 你可以看看这里:http://iloverep.dk/produkt/iphone-6s-plus-original-skaerm/ –

相关问题