JQ延时模糊查询

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=ul, initial-scale=1.0">
    <title>Document</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>

<body>
    <input type="text" id="filterName">
    <ul>
        <li>545</li>
        <li>231</li>
        <li>1</li>
        <li>541</li>
        <li>4454</li>
        <li>8</li>
        <li>874</li>
        <li>6</li>
        <li>54654</li>
        <li>菜单1</li>
        <li>菜单2</li>
        <li>菜单3</li>
        <li>菜单4</li>
        <li>菜单5</li>
        <li>菜单6</li>
        <li>菜单7</li>
        <li>菜单8</li>
    </ul>
</body>

<script>
    $(function() {
        var timer;
        $("#filterName").keyup(function() {
            clearTimeout(timer);
            var that = this
            timer = setTimeout(function() {
                $("li")
                    .hide()
                    .filter(":contains('" + ($(that).val()) + "')")
                    .show();
            }, 2000);
        });
    });
</script>

</html>

 

posted @ 2021-02-08 17:13  小夜猫啊  阅读(52)  评论(0编辑  收藏  举报