我正在使用 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 + "%");
关于javascript - 使用jquery初始化 Bootstrap 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42223681/