Jquery //将单词添加到位置数组 位置。推送(“.”+文本); //检查是否具有.propertytype }else if($(this.parent().hasClass('propertytype')){ //获取数据id属性 properties.push
//将单词添加到位置数组 位置。推送(“.”+文本); //检查Jquery //将单词添加到位置数组 位置。推送(“.”+文本); //检查是否具有.propertytype }else if($(this.parent().hasClass('propertytype')){ //获取数据id属性 properties.push,jquery,Jquery,//将单词添加到位置数组 位置。推送(“.”+文本); //检查是否具有.propertytype }else if($(this.parent().hasClass('propertytype')){ //获取数据id属性 properties.push(“.”+$(this.data('id')); } }); //如果数组为空,则显示所有内容 如果(locations.length您的location li数据id和表行的关系是什么?您试图筛选location li数据id并在表中搜索相关
如果(locations.length您的location li数据id和表行的关系是什么?您试图筛选location li数据id并在表中搜索相关类。但在当前输入的数据中没有此类类。@Lasithds抱歉,我忘了解释由于不同数量的特殊字符和空格。我将编辑此问题。您好@KL_u。此解决方案看起来很棒。如果我想扩展此代码段以包含其他筛选器,我可以问一下:.agentname li、.beddrooms li、.salerent li'我将如何处理此问题。您可以编辑您的解决方案吗?您应该创建数组以保存
的信息在上,然后将类添加到$()。每个
函数(类似于$('.beddrooms li,.salerorrent li'…)
,并在其中验证他是否拥有在将信息插入特定数组之前需要过滤的类。之后,只需使用属性数组处理的相同格式。
<ul class="location" multiple="">
<li data-id="term_87" class="">Cannes</li>
<li data-id="term_88">Cap d'Antibes & Juan les Pins</li>
<li data-id="term_133" class="">Eze</li>
</ul>
<ul class="propertytype others" multiple="">
<li data-id="villa">Villa</li>
<li data-id="hotel">Hotel</li>
<li data-id="hotelVillas">Hotel Villas</li>
</ul>
<table class="elegant_list_properties">
<tr id="1" class="propertyrow cannes villa">
<td>some stuff</td>
</tr>
<tr id="2" class="propertyrow cannes hotel">
<td>some stuff</td>
</tr>
<tr id="3" class="propertyrow eze villa">
<td>some stuff</td>
</tr>
<tr id="4" class="propertyrow london villa">
<td>some stuff</td>
</tr>
<tr id="5" class="propertyrow paris hotel">
<td>some stuff</td>
</tr>
</table>
//For the location filters
jQuery('.elegant_filters ul li').on('click', function(e){
jQuery(this).toggleClass('selected');
var filters = [];
jQuery('.elegant_filters ul li.selected').each(function(){
var val = jQuery(this).attr('data-id');
filters.push('.'+val);
});
console.log(filters);
if (jQuery(filters).length < 1) {
jQuery('.elegant_list_properties tr.propertyrow').show();
} else {
jQuery('.elegant_list_properties tr.propertyrow').hide();
jQuery(filters.join(', ')).show();
}
})