我有一个 Bootstrap 进度条,显示用户的熟练程度(基本上,正确响应超过尝试)。但是,我想用两个条标记差异,一个标记为“bg-success”,另一个标记为“bg-warning”,以使对比更加明显。我用不同 ID 的进度条来做到这一点。问题是进度条不会出现在同一行上。
下面的代码显示了我所在的位置,我已经尝试了所有可以修复它的重新标记尝试,但都无济于事。
这是相关的 JavaScript:
function setBars() {
var profPerc = Number(((myProg[1] / myProg[2]) * 100).toFixed(csvSize.toString().length));
document.getElementById("profBar").innerHTML = "<strong>" + profPerc.toString() + "</strong>";
document.getElementById("profBar").style.width = profPerc + "%";
document.getElementById("offBar").innerHTML = "<strong> </strong>";
document.getElementById("offBar").style.width = (100 - profPerc) + "%";
}
// There are no errors with any of the other above-mentioned variables.
这是相关的 HTML:
<div class="proficiencydiv">
<div class="progress-bar bg-success" role="progressbar" id="profBar" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-warning" role="progressbar" id="offBar" aria-valuemin="0" aria-valuemax="100"></div>
</div>
我希望得到如下所示的结果:
"[profBar][offBar]".
相反,我得到:
"[profBar]"
"[offBar]"
最佳答案
添加到 css 下方
.proficiencydiv{
display: flex}
.proficiencydiv{
display: flex}
.proficiencydiv div{
margin: 10px}
<div class="proficiencydiv">
<div class="progress-bar bg-success" role="progressbar" id="profBar" aria-valuemin="0" aria-valuemax="100">profBar</div>
<div class="progress-bar bg-warning" role="progressbar" id="offBar" aria-valuemin="0" aria-valuemax="100">offBar</div>
</div>
关于javascript - 如何在同一行上获得多个具有不同 ID 的进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56289535/