完成ajax调用后无法删除进度条

时间:2017-11-17 06:29:10

标签: javascript jquery ajax

我做错了什么?

progressbar : function() { 
    var $progress = $('<div>', {'class' : 'progress-bar', height : '2px'});
    var width = 0,
        load  = 0;
    $(document).on({ 
        ajaxSend : function(event, req, set) {
            $('body').append($progress);            
            load = setInterval(function(e) {
                if (width > 100) {
                    clearInterval(load);
                }
                width++;
                $('.progress-bar').width(width + '%');
            }, 10);
        },
        ajaxComplete : function(){
            width = 0;
            clearInterval(load);
            $('body').remove('.progress-bar');
            //$('.progress-bar').fadeOut();
        }
    });
}

fadeOut函数有效但我无法从DOM中删除.progress-bar。我在窗口上调用上面的函数 - load&amp;点击。

2 个答案:

答案 0 :(得分:1)

$('body').remove('.progress-bar'); 

替换它
$('.progress-bar').remove();

答案 1 :(得分:1)

您必须使用$('.progress-bar').remove()

相关问题