我可以参考输入:文本是否为#id?

问题描述:

我正在创建一个“过滤输入字段”,用于消除不匹配输入的页面中的图块。我可以参考输入:文本是否为#id?

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

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

我认为你正在寻找:

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

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

+0

作品...... ROCK ON! – 2013-05-08 17:10:50

尝试了这一点:

$('article:not(:contains("' + filter_text + '"))').fadeOut(); 
+0

这不会淡出符合过滤文本的文章吗? – tymeJV 2013-05-08 17:09:25

+0

@tymeJV oops。一秒 – Neal 2013-05-08 17:09:40

+0

我修正了它:-)。 – Neal 2013-05-08 17:10:08