我尝试使用 java 脚本更改 Bootstrap 进度条的宽度,但没有成功。我在 head 部分编写了这段代码。请指教。
document.getElementsByClassName("progress-bar").setAttribute("style", "width:50%");
document.getElementsByClassName("progress-bar").style.width = "width:50%";
HTML :
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
</div>
</div>
最佳答案
getElementsByClassName() 将返回一个节点列表,您应该指定要更改的节点的索引:
document.getElementsByClassName("progress-bar")[0].setAttribute("style", "width:50%");
document.getElementsByClassName("progress-bar")[0].style.width = "50%";
希望这对您有所帮助。
关于javascript - 使用javascript更改进度条的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35552197/