input输入框输入延时请求(时时搜索)

当input正在获得焦点时停1s在请求

        var timeoutId = 0;
        $('#id').off('keyup').on('keyup', function (event) {
            clearTimeout(timeoutId);
            timeoutId = setTimeout(function () {
                    $.ajax({
                        url: '__MODULE__/Base/getSearchStation',
                        dataType: 'json',
                        data: {'search': ''},
                        type: 'POST',
                        success: function (re) {
                           //do something
                        }
                    });
            }, 1000);
        });

猜你喜欢

转载自blog.csdn.net/pwjiferox/article/details/79415439