我知道插件已经存在,而且已经制作好了,然而,我想自己制作一个。我被困住了,因为我是jQuery/JavaScript的新手。
现在,无论您键入多少个字符,整个页面都会消失,而不是显示包含我键入的字符的单词。我做错了什么?
<div class="searchOption">
<input type="text" id="search" placeholder="search">
</div>
<div class="searchFound">
<!--upon hitting enter, this div opens collapse. -->
</div>
/*Need to get the below search code working...*/
var thePage = $(".pageContainer");
$("#search").keyup(function(){
var input = $(this).val();
console.log(input);
//if match found, make corresponding div link appear in open collapsible div,
// else say nothing found in open collapsible div
thePage.each(function(index, value){
var foundText = $(this).text().toLowerCase();
$(value).toggle(foundText.indexOf(input) >= 0);
});
});
我知道thePage会让事情变得“切换”,因为没有更好的词了,然而,当我使用closest或match时,toggle什么也不做。
我正在寻找一些指导来帮助我构建这个。谢谢!
https://stackoverflow.com/questions/38127815
复制相似问题