1

我正在寻找创建一个“过滤输入字段”,以消除页面中与输入不匹配的图块。

到目前为止,我有这个...

HTML -

<input name="filter" type="text" value="Find who you're looking for" />
<a href='#' id='b_submit'>Submit</a>

<article id='JohnS'>Content</article>
<article id='BobG'>Content</article>
<article id='SamL'>Content</article>
<article id='RonaldY'>Content</article>

脚本 -

$("#b_submit").click(function() {

    var filter_text = $('input:text').val();
    //this sets filter_text as the input value

    $('article:not(??not sue what to call here??)').fadeOut();
    //this is where I need help, I need to call the value as an #id to eliminate non-matching articles. 

    });

这样做的正确语法是什么?我是否过于复杂了简单的过滤?帮助?:D

4

2 回答 2

5

我想你正在寻找:

$('article:not(#'+filter_text+')').fadeOut();

演示:http: //jsfiddle.net/GKj66/

于 2013-05-08T17:07:10.873 回答
3

试试这个:

$('article:not(:contains("' + filter_text + '"))').fadeOut();
于 2013-05-08T17:07:31.327 回答