📜  输入搜索图片 jquery - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:20.906000             🧑  作者: Mango

代码示例2
$(document).ready(function() {
  var images = $(".item") //contain all unfiltered images
  $("#filter").on("change paste keyup", function(){
      $.each(images, function(i, l){
          $(l).hide();
      }); //hide all images
      searchValue = $("#filter").val(); //get entered value of input field
    searchValueRE = new RegExp(searchValue, "i"); //convert search value into RegExp
    output = $.grep(images, function (n) {return searchValueRE.test(n.className); }); //Returns array that matches input value
    $.each(output, function(i, l){
          $(l).show();
      }); //show matched images
  });
});