Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 通过单击清除输入搜索_Jquery_Search_Input_Reset - Fatal编程技术网

Jquery 通过单击清除输入搜索

Jquery 通过单击清除输入搜索,jquery,search,input,reset,Jquery,Search,Input,Reset,我有一个小脚本,它通过使用搜索字段的“alt”标记来显示图像 现在,我尝试通过单击按钮来清除搜索(而不仅仅是清空输入字段) 但我只能在字段内按键盘上的“delete”键完全重置。我做错了什么 $(“#搜索”)。在(“键控”,函数()上{ 如果($(this.val().length>0){ $(“.image”).hide(); var mySelector=$(this.val(); var myImgs=$(“[alt*=”+mySelector+“'i]”); myImgs.show();

我有一个小脚本,它通过使用搜索字段的“alt”标记来显示图像

现在,我尝试通过单击按钮来清除搜索(而不仅仅是清空输入字段)

但我只能在字段内按键盘上的“delete”键完全重置。我做错了什么

$(“#搜索”)。在(“键控”,函数()上{
如果($(this.val().length>0){
$(“.image”).hide();
var mySelector=$(this.val();
var myImgs=$(“[alt*=”+mySelector+“'i]”);
myImgs.show();
}否则{
$(“.image”).show();
}
});

不,没那么容易。我必须进一步解释一下。在网页上有一个功能,用户可以通过两种方式搜索品牌:通过categroy(带有筛选脚本的下拉菜单)和使用搜索字段。以下是完整的脚本:

    //Brands Filter 
    var $btns = $('.btn-brand').click(function () {
  if (this.id == 'all') {
    $('.brand').removeClass('brand-off');
  } else {
    var $el = $('.' + this.id).removeClass('brand-off');
    $('.brand').not($el).addClass('brand-off');
  }

  $btns.removeClass('btn-brand-active');
  $(this).addClass('btn-brand-active');

});


//Free Search
$("#search").on("keyup", function() {
  if ($(this).val().length > 0) {
    // hide everything,
    $(".brand").hide();
    // get the text in the input
    var mySelector = $(this).val();
    // show any alt that contains the input
    var myImgs = $("[alt*='"+mySelector+"' i]");
    myImgs.show();
  } else {
    $(".brand").show();
  }
  });

因此,如果我使用搜索字段,并且在使用该下拉列表之后,我不会得到所有结果,直到我在搜索字段中单击“删除”按钮手动清除搜索字段。

按钮单击代码在哪里?这是与问题相关的部分。$(“.button”)。单击(function(){$('#search').val(“”;});因此,您只需再次显示所有图像,
$('.image').show()
。。。