【问题标题】:SimpleCart.js search functionalitySimpleCart.js 搜索功能
【发布时间】:2014-07-11 16:12:44
【问题描述】:

使用 simpleCart 已经有一段时间了,效果很好,我知道它有搜索功能,但它似乎只搜索某些元素我的问题是,我想知道它是否可以设置为搜索在 html 文件的内容中?因为所有项目都存储在 Html 页面中以便于简单编目。

【问题讨论】:

    标签: simplecart


    【解决方案1】:

    试试这个: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();"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 2017-08-05
      • 2015-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多