【问题标题】:jQuery Mobile Search Hide Search OptionsjQuery Mobile 搜索隐藏搜索选项
【发布时间】:2013-07-18 03:26:40
【问题描述】:

在输入某些内容之前,我不希望显示任何搜索内容。我将类隐藏,然后在搜索项目时使用 .show(),但是它不起作用。

演示:http://jsfiddle.net/DyYFb/207/

JS:

$("#search").keyup(function(){

var SEARCHWORD = this.value;
$("#list li").each(function(){

    if($(this).
          find("h3, p").
          text().toUpperCase().
          indexOf(SEARCHWORD.toUpperCase()) >=0)
   $(this).show();
    else
   $(this).hide();

});


});

【问题讨论】:

    标签: javascript jquery html search mobile


    【解决方案1】:

    这是您可能正在寻找的东西jsFiddle Example

    我只是在你的代码中添加了一些内容,所以我没有很好地格式化它。您可以改回.slideUp().slideDown()。我只是更喜欢他们。

    $('#list li').hide(0); //Hide the elements initially
    
    $("#search").keyup(function(){
    
        var SEARCHWORD = $.trim(this.value);
    
        if(SEARCHWORD === ""){            //Checks if Search Term is Nothing and starts over
            $('#list li').slideUp(150); 
            return false;
        } 
    
        $("#list li").each(function(){
    
        if($(this).
              find("h3, p").
              text().toUpperCase().
              indexOf(SEARCHWORD.toUpperCase()) >=0)
         $(this).slideDown(150);
        else
          $(this).slideUp(150);
    
     });
    

    });

    【讨论】:

    • 由于某种原因,当我将它与我的所有其他代码结合起来时,它不起作用
    • 有什么方法可以私聊你
    • 我运行的jquery版本有问题吗?
    • @nshah 我不确定,但我真的要去睡觉了。对不起。您可以随时将其作为另一个问题发布。另外我明天可以回来查看
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多