当我开始打字时,缩小搜索结果的范围

Narrow down the search result when I start typing

本文关键字:缩小 搜索结果 范围 开始      更新时间:2023-09-26

我在这里寻找创意。。我会尝试用你的想法进行编码,如果我有任何问题,请告诉你。。

问题

页面上有一个文本框和姓名列表。当我开始打字时,我希望搜索结果应该缩小。当我在文本框中键入"a"时,结果应该缩小,并且应该只包含带"a"的名称s。

请告诉我jquery中是否有可用的方法???

尝试jQuery UI的自动完成。

类似这样的东西:

    $('#search').on('keyup', function () {
       var str = $('#result ul li:contains(' + $(this).val().charAt(0).toUpperCase() + ')');
       if (str) {
          $('#result ul li').hide();
          str.show();
       } else {
          $('#result ul li').show();
       }
    });