javascript - Twitter Bootstrap 风格 = "width: 45%;"

标签 javascript html css twitter-bootstrap

在使用 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/

相关文章:

javascript - Summernote 将字体大小添加到工具栏

javascript - 如何监听另一个对象的事件发射?

javascript - JS 将对象推送到变量将最后一个对象添加到所有元素

HTML 对齐问题 : making rows and columns using div : float tag

html - IE6 和 8 中的 CSS3PIE 问题

jquery - 从 div 切出的 CSS 椭圆形

javascript - Dojo 模块加载一般情况

javascript - 如何在 jQuery/javascript 中正确使用 if then else 语句?

javascript - 无法根据 z 索引使 iframe 内容与相邻的 div 重叠

java.net.URL 引用 CSS