已经使用 simpleCart 一段时间了,效果很好,我知道它有搜索功能,但它似乎只搜索某些元素我的问题是这个,我想知道它是否可以设置为在内容中搜索的 html 文件?因为所有项目都存储在 Html 页面中以进行简单的编目。
1 回答
0
试试这个:JS
function filter(e){
search = e.value.toLowerCase();
console.log(e.value)
document.querySelectorAll('.item_name').forEach(function(row){
text = row.innerText.toLowerCase();
if(text.match(search)){
row.style.display="block"
} else {
row.style.display="none"
}
// need to count hidden items and if all instances of .kb-items are hidden, then hide .kb-item
var countHidden = document.querySelectorAll(".item_name[style='display: none;']").length;
console.log(countHidden);
})
}
function detectParent()
{
var collectionref=document.querySelectorAll(".simpleCart_shelfItem");
collectionref.forEach(group=>{
var itemcollection=group.getElementsByClassName("item_name");
var hidecounter=0;
for(var j=0;j<itemcollection.length;j++)
{
if(itemcollection[j].style.display==='none')
{
hidecounter++;
}
}
if(hidecounter===itemcollection.length)
{
group.style.display="none";
}else{
group.style.display="block";
}
});
}
和 HTML:
<input type="text" onkeyup="filter(this);detectParent();"/>
于 2019-08-22T16:28:17.043 回答