试图替换django项目中呈现的每个项目的百分比圆的笔触颜色。到目前为止,我只设法将颜色更改为红色。我怀疑这是因为它根据检索到的第一个/最后一个记录(百分比),将它们更改为全部。jQuery - 根据数值更改颜色并逐个遍历每个项目
有没有一种方法来遍历jQuery中的每个项目,以便每个项目的笔触颜色会改变?
的jQuery:
$(function() {
var score = parseInt($("#percentage").text());
if (score <=40) {
$("path").css("color", "red")
} else if (score >=40) {
$("path").css("color", "green")
}
});
HTML:
{% extends "base.html" %}
{% load bootstrap_tags %}
{% load staticfiles %}
{% block head_js %}
<script src="{% static "js/percentage.js" %}"></script>
{% endblock %}
{% block content %}
{% for statistic in statistics %}
<div class="stat_img">
<img width="100%" src="/media/{{statistic.image}}">
</div>
<span id="percentage">{{statistic.percentage}}</span>
<div class="stat_ranking">
<span class="stat_title">{{statistic.title}} ({{statistic.year}})</span>
<br>
<svg viewbox="0 0 36 36" class="circular-chart">
<path class="circle" stroke-dasharray="{{statistic.percentage}}, 100"
d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"/>
<text x="50%" y="40%" text-anchor="middle" dy=".3em">{{statistic.percentage}}%</text>
<text class="blue" x="50%" y="55%" text-anchor="middle" dy=".3em">{{statistic.rating}}</text>
</svg>
</div>
<div class="statistics">
Genre: {{statistic.genre}} <br>
Box Office: ${{statistic.box_office}} <br>
Budget: ${{statistic.budget}}
</div>
<hr>
{% endfor %}
{% endblock %}
想知道什么路径? –
如果你分享你的html代码,它会更清楚地回答它。 – Jayground