Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery创建过滤器按钮_Jquery - Fatal编程技术网

使用jQuery创建过滤器按钮

使用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

我想为我的帖子创建过滤按钮,这是我的html代码

<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')