Filter search for

    前端 未结 1 467
    滥情空心
    滥情空心 2020-12-30 08:58

    I have a list of users as well:

    1条回答
    •  慢半拍i
      慢半拍i (楼主)
      2020-12-30 09:20

      Here is a input that filters a

        based on the value in pure JavaScript. It works by handling the onkeyup and then getting the
      • s and comparing their inner element .name with the filter text.

        jsFiddle

        enter image description here

        var input = document.getElementById('input');
        input.onkeyup = function () {
            var filter = input.value.toUpperCase();
            var lis = document.getElementsByTagName('li');
            for (var i = 0; i < lis.length; i++) {
                var name = lis[i].getElementsByClassName('name')[0].innerHTML;
                if (name.toUpperCase().indexOf(filter) == 0) 
                    lis[i].style.display = 'list-item';
                else
                    lis[i].style.display = 'none';
            }
        }
        

      0 讨论(0)
    提交回复
    热议问题