如何显示进度栏的百分比

发布于 2025-02-06 06:34:26 字数 1097 浏览 5 评论 0 原文

因此,我正在尝试在一个页面上显示每个栏的百分比,这是我的进度条的HTML:

<div class="col-md-5">
<p>Progress bar1</p>
  <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 50%;"></div>
 </div>
 <p>Progress bar2</p>
 <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 20%;"></div>
 </div>
 <p>Progress bar3</p>
 <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 30%;"></div>
 </div>

这是我使用此栏的JS功能,

$(document).ready(function() {
 $(".progress-bar").each(function(index) {
//if(index >=0 && index<=1)
//{
$(this).animate({
  width: Math.floor((Math.random() * 100) + 1) + "%"
}, 2500);

//        }
})
});

我得到的所有栏都是自动生成的,但是我想显示每个条的百分比酒吧,我该怎么做? 这是 fiddle

So I'm trying to display the percentage of each bar on one page, here is the HTML for my progress bars:

<div class="col-md-5">
<p>Progress bar1</p>
  <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 50%;"></div>
 </div>
 <p>Progress bar2</p>
 <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 20%;"></div>
 </div>
 <p>Progress bar3</p>
 <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 30%;"></div>
 </div>

and this is my js function

$(document).ready(function() {
 $(".progress-bar").each(function(index) {
//if(index >=0 && index<=1)
//{
$(this).animate({
  width: Math.floor((Math.random() * 100) + 1) + "%"
}, 2500);

//        }
})
});

using this i get all bars are automated generated, but i want to display the percentage of each bar, how i can do this ?
This the fiddle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莳間冲淡了誓言ζ 2025-02-13 06:34:28

当您使用Bootstrap 3时,您可以将百分比添加到“ .progress-bar” div:

$( document ).ready(function() {
    $(".progress-bar").each(function (index ) {
        //if(index >=0 && index<=1)
        //{
            var percent = Math.floor((Math.random() * 100) + 1) + "%";
            $(this).html(percent);
            $(this).animate({width: percent}, 2500);
             
//        }
    })
}); 

您的jsfiddle扩展

As you using Bootstrap 3, you can add the percentage to the ".progress-bar" div:

Bootstrap docs

$( document ).ready(function() {
    $(".progress-bar").each(function (index ) {
        //if(index >=0 && index<=1)
        //{
            var percent = Math.floor((Math.random() * 100) + 1) + "%";
            $(this).html(percent);
            $(this).animate({width: percent}, 2500);
             
//        }
    })
}); 

Your jsfiddle extended

迷乱花海 2025-02-13 06:34:28

您可以在DIV本身内添加百分比文本。检查下面的代码:

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

You can add the percentage text inside the div itself. Check the code below :

<div class="progress progress-striped active">
  <div class="progress-bar progress-bar-Success" style="width: 50%;"> 50 </div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文