使用jQuery初始化引导程序进度栏



我正在使用bootstrap进度栏,该步骤设置为零

  <div class="progress-bar progress-bar-success" id="p1"
    role="progressbar" aria-valuenow="0"
    aria-valuemin="0" aria-valuemax="100" style="width:0%">

我使用以下jQuery代码来初始化进度栏

    $.ajax({
        type: "POST",
        dataType: "json",
        url: "myurl.php",
        data: data
    }).done(function(msg) {
    console.log(msg);
    var pid = msg.pid;
    var colour = msg.colour;
    var comp = msg.comp;
    console.log('pid = ' + pid);
    console.log('colour = ' + colour);
    document.getElementById(pid).style.width = comp;
    document.getElementById(pid).innerHTML = comp + '% Complete';   
    document.getElementById(pid).classList.add(colour); 
    });

我从AJAX请求中获取有效数据,

Object {pid: "p1", comp: 7, colour: "progress-bar-success"}

但是,进度栏不会更新。如果我将HTML中的栏初始化为1%,则使用上述代码来工作。有没有办法使用jQuery?

进行初始化

设置进度栏的宽度时必须添加"%";

document.getElementById(pid).style.width = comp + "%";

jQuery解决方案

$("#"+pid ).css('width', comp + "%");

最新更新