你的意思是如何改变颜色为在运行时彼此?
我只能想象你这样做,因为你没有标记任何人是正确的。在你的意思是这样的话,那么看看这个很小的jsfiddle
HTML
<div class="progress">
<div class="bar bar-success" style="width: 0%; opacity: 1;"></div>
</div>
JS
jQuery(document).ready(function(){
window.percent = 0;
window.progressInterval = window.setInterval(function(){
if(window.percent < 100) {
window.percent++;
jQuery('.progress').addClass('progress-striped').addClass('active');
jQuery('.progress .bar:first').removeClass().addClass('bar')
.addClass ((percent < 40) ? 'bar-danger' : ((percent < 80) ? 'bar-warning' : 'bar-success')) ;
jQuery('.progress .bar:first').width(window.percent+'%');
jQuery('.progress .bar:first').text(window.percent+'%');
} else {
window.clearInterval(window.progressInterval);
jQuery('.progress').removeClass('progress-striped').removeClass('active');
jQuery('.progress .bar:first').text('Done!');
}
}, 100);
});
http://jsfiddle.net/LewisCowles1986/U9xw6/
请考虑为了不成为未来的链接无用的答案编辑你的答案。 – 2016-11-13 02:50:03
嗨Leandro。我的观点是:“不要在你的js中搞乱颜色,你可以将元素类改为进度 - 不管这是由bootstrap提供的预定义类。我确定有很多问题可以解释如何在运行时更改元素上的css类。如果你喜欢剪切和粘贴看看其他答案。 – 2016-11-13 05:25:55
感谢您的回复。实际上,我问你的是SO中的一个等级规则。 – 2016-11-13 18:52:24