我有链接列表:
<p>Use our search bar to narrow the list.</p>
<input id="sitemap-search" placeholder="Type to narrow list"><br>
<a class="sitemap" href="/49/brown-zircon-gemstones/s/1/round">ROUND BROWN ZIRCON GEMSTONES</a><br>
<a class="sitemap" href="/49/brown-zircon-gemstones/s/2/cushion">CUSHION BROWN ZIRCON GEMSTONES</a><br>
<a class="sitemap" href="/49/brown-zircon-gemstones/s/3/oval">OVAL BROWN ZIRCON GEMSTONES</a><br>
<a class="sitemap" href="/49/brown-zircon-gemstones/s/4/emerald-cut">EMERALD-CUT BROWN ZIRCON GEMSTONES</a><br>
和一些javascript:
$('#sitemap-search').on('keyup',function(){
var keys = $(this).val();
$.each($('.sitemap'),function(i,item){
console.log($(item).text());
if(!keys.toUpperCase().indexOf( $(item).text() )){
$(item).hide();
} else {
$(item).show();
}
});
});
我要完成的工作是根据关键字输入来缩小链接列表。
因此,如果您输入cu,它将隐藏其他两个链接
有人想要帮助我吗?谢谢!
答案 0 :(得分:0)
使用:
$('#sitemap-search').on('keyup',function(){
var keys = $(this).val();
$.each($('.sitemap'),function(i,item){
if($(item).text().search( keys.toUpperCase() ) > -1){
$(item).show();
} else {
$(item).hide();
}
});
});