使用jQuery创建过滤器按钮
我想为我的帖子创建过滤按钮,这是我的html代码使用jQuery创建过滤器按钮,jquery,Jquery,我想为我的帖子创建过滤按钮,这是我的html代码 <div id='filter'> <button class='arts'>Arts</button> <button class='sport'>Sports</button> <button class='games'>Games</button> </div> <div id='posts'> &l
<div id='filter'>
<button class='arts'>Arts</button>
<button class='sport'>Sports</button>
<button class='games'>Games</button>
</div>
<div id='posts'>
<div class='post sport'></div>
<div class='post arts'></div>
<div class='post games'></div>
<div class='post games sport'></div>
<div class='post arts'></div>
<div class='post sport'></div>
<div class='post games'></div>
</div>
但是这对我不起作用,所以请告诉我正确的方法,您传入的是文本字符串“filtertag”,而不是变量,因此您需要执行以下操作:
$('.post').show(); // Show all posts
$('.post:not(.' + filtertag + ')').hide(); // Hide the ones you don't want
您传入的是文字字符串“filtertag”,而不是变量,因此需要执行以下操作:
$('.post').show(); // Show all posts
$('.post:not(.' + filtertag + ')').hide(); // Hide the ones you don't want
您传入的是文字字符串“filtertag”,而不是变量,因此需要执行以下操作:
$('.post').show(); // Show all posts
$('.post:not(.' + filtertag + ')').hide(); // Hide the ones you don't want
您传入的是文字字符串“filtertag”,而不是变量,因此需要执行以下操作:
$('.post').show(); // Show all posts
$('.post:not(.' + filtertag + ')').hide(); // Hide the ones you don't want
试试这段代码。您可能需要更改jQuery选择器才能使用live站点
$(“按钮”)。单击(函数(){
var show=$(this.attr('class');
$('.post')。每个(函数(){
$(this.show();
var test=$(this.attr('class');
if(test.indexOf(show)<0)$(this.hide();
});
});
试试这段代码。您可能需要更改jQuery选择器才能使用live站点
$(“按钮”)。单击(函数(){
var show=$(this.attr('class');
$('.post')。每个(函数(){
$(this.show();
var test=$(this.attr('class');
if(test.indexOf(show)<0)$(this.hide();
});
});
试试这段代码。您可能需要更改jQuery选择器才能使用live站点
$(“按钮”)。单击(函数(){
var show=$(this.attr('class');
$('.post')。每个(函数(){
$(this.show();
var test=$(this.attr('class');
if(test.indexOf(show)<0)$(this.hide();
});
});
试试这段代码。您可能需要更改jQuery选择器才能使用live站点
$(“按钮”)。单击(函数(){
var show=$(this.attr('class');
$('.post')。每个(函数(){
$(this.show();
var test=$(this.attr('class');
if(test.indexOf(show)<0)$(this.hide();
});
});
这应该可以做到;不需要使用。每个循环将事件侦听器附加到按钮
$('.post').hide();//if you want them hidden to start with
$("#filter button").on("click", function(){
var filtertag = $(this).attr('class');
$('.post').hide().filter('.' + filtertag).show();
})
[0].click();//if you want them filtered by first button on load
这应该可以;不需要使用。每个循环将事件侦听器附加到按钮
$('.post').hide();//if you want them hidden to start with
$("#filter button").on("click", function(){
var filtertag = $(this).attr('class');
$('.post').hide().filter('.' + filtertag).show();
})
[0].click();//if you want them filtered by first button on load
这应该可以;不需要使用。每个循环将事件侦听器附加到按钮
$('.post').hide();//if you want them hidden to start with
$("#filter button").on("click", function(){
var filtertag = $(this).attr('class');
$('.post').hide().filter('.' + filtertag).show();
})
[0].click();//if you want them filtered by first button on load
这应该可以;不需要使用。每个循环将事件侦听器附加到按钮
$('.post').hide();//if you want them hidden to start with
$("#filter button").on("click", function(){
var filtertag = $(this).attr('class');
$('.post').hide().filter('.' + filtertag).show();
})
[0].click();//if you want them filtered by first button on load
这个$('.post outer')
应该选择什么?对不起,我是说$('.post')
这个$('.post outer')
应该选择什么?对不起,我是说$('.post outer')
这个$('.post outer')
应该选择什么?对不起,我是指$('.post outer')
这个$('.post outer')是什么
应该选择吗?对不起,我是说$('.post')