在使用 Twitter Bootstrap 中的进度栏时,我想设置一个发送到样式宽度参数的变化变量:
<div class="progress progress-striped">
<div class="bar" style="width: 20%;"></div>
</div>
我希望能够在从数据库文件获取百分比数字后更改宽度。
例如,如果从数据库检索到的数字是 80,我会将 80 合并到样式的百分比部分中:
style=“宽度:80%;”
我尝试过在 HTML 中使用 Javascript 中的变量,但进展并不顺利。
感谢您的帮助,
汤米
最佳答案
希望这个答案有所帮助,我喜欢解释执行您想要的任务的 JavaScript 和 jQuery 方法。
jQuery 方法:
$(document).ready(function() {
var progWidth = /* The way you'd access the database file to obtain the percent. */
$('.progress-striped > .bar').width(progWidth + "%");
});
纯 JavaScript 方法:
document.onload = function() {
var progWidth = /* The way you'd access the datbase file to obtain the percent. */
$('.progress-striped > .bar').width(progWidth + "%");
}
关于javascript - Twitter Bootstrap 风格 = "width: 45%;",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19338768/