【发布时间】:2019-12-04 18:49:12
【问题描述】:
当工作正常时我有一个进度条,但我想要实现的是如果百分比低于 50%,我希望进度条从绿色变为红色。我在 jQuery 中工作,但没有得到结果,请问我可以得到一些帮助吗?
提前致谢
<td>
<span class="header-text">
<div class="progress-bar progress-bar-success progress-bar-striped active progressbartextcolor" id="below50percent" role="progressbar" aria-valuenow="25" aria-valuemin="0" v-bind:style="{width: customerLoan.progress + '%'}" aria-valuemax="100">{{customerLoan.progress || "0"}}%</div>
</span>
</td>
<script>
$(document).ready(function(){
var bars =
$('{{customerLoan.progress}}');
for (i = 0; i < bars.length; i++)
{
console.log(i);
var progress = $(bars[i]).attr('{{customerLoan.progress}}');
$(bars[i]).width(progress + '%');
if (progress <= "50")
{
$(bars[i]).addClass("progress-bar-danger");
}
}
});
</script>
【问题讨论】:
-
我很确定
$('{{customerLoan.progress}}');不会做你认为它做的事情,以及其他问题。我猜你使用某种插件?你使用把手的事实让我觉得你也在使用某种模板引擎?也许是角?我们需要一个minimal reproducible example。我的猜测是,您无法使用 jquery 与之交互 -
无法理解 {{customerLoan.progress}} 是什么,这里的想法很简单,根据您只需要从元素中添加/删除所需类的进度
-
{{customerLoan.progress}} 指定宽度。
-
那么你为什么要尝试使用宽度作为 jquery 选择器?你期望它匹配什么?我建议您阅读 jquery 选择器的工作原理,因为这根本不起作用api.jquery.com/category/selectors
标签: javascript jquery vue.js