Jquery如何获取加载内容的百分比?

时间:2016-07-22 03:09:30

标签: javascript php jquery html

这是我的代码

$(document).ready(function(){
$("#upload").click(function(){

    var request = new XMLHttpRequest();
    request.open('GET', document.location, false);
    request.send();
    var size = request.getAllResponseHeaders().toLowerCase().match(/content-length: \d+/);
    alert(size);
    var value;

    if(size)
    {
        value = 100;
    }

    // $("div#divLoading").addClass('show');
    $('#progress-bar2').html( value + '%');
    $('#progress-bar2').attr('style','width:'+ value + '%');
});

});

<div class="progress" id="progress-bar">
    <div class="progress-bar progress-bar-striped active" role="progressbar" id="progress-bar2" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
    <div class="percent">0%</div>
                <div id="status"></div>
            </div>
        </div>

我的问题是如何获得加载页面内容的百分比?我想用它来动态填充var值并使进度条工作。对此问题的任何建议?

0 个答案:

没有答案