Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Twitter引导风格=”;宽度:45%&引用;_Javascript_Html_Css_Twitter Bootstrap - Fatal编程技术网

Javascript Twitter引导风格=”;宽度:45%&引用;

Javascript Twitter引导风格=”;宽度:45%&引用;,javascript,html,css,twitter-bootstrap,Javascript,Html,Css,Twitter Bootstrap,在使用Twitter引导的进度条时,我想设置一个发送到style width参数的变化变量: <div class="progress progress-striped"> <div class="bar" style="width: 20%;"></div> </div> 我想能够改变宽度后,获得一个百分比数字从数据库文件 例如,如果从数据库检索到的数字是80,则我会将80合并到样式的百分比部分: style=“宽度:80%;” 我曾尝

在使用Twitter引导的进度条时,我想设置一个发送到style width参数的变化变量:

<div class="progress progress-striped">
  <div class="bar" style="width: 20%;"></div>
</div>

我想能够改变宽度后,获得一个百分比数字从数据库文件

例如,如果从数据库检索到的数字是80,则我会将80合并到样式的百分比部分:

style=“宽度:80%;”

我曾尝试在HTML中使用Javascript中的变量,但进展不太快

谢谢你的帮助


Tommy

将百分比放在一个var中,并在javascript或jQuery中使用它。我将使用jQuery:

$(document).ready(function() {
    var theWidth = // Wherever you get the var;
    $(".progress-striped > .bar").width(theWidth + "%");
});

为了详细说明“您的var”部分,我们需要知道您是如何获得数据库信息的。

希望这个答案有所帮助,我想解释一下执行您想要的任务的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 + "%");
}

Ftr,这样宽度将被解释为px,而不是百分比。@nietonfir谢谢。我不认为第二个解决方案是纯javascript,因为$('.progress striped>.bar')是一个jquery方法