我将如何迭代类名student-week-diff,如果该值小于或大于0,则将该类从student-week-diff更改为fa-level-up(如果大于0)和fa-level-down(如果小于0)
这是我的html表,我已经定义了一个类名为student-week-diff
<table class="table table-hover" id="studentweek">
<thead>
<tr>
<th>Year</th>
<th>Weeks</th>
</tr>
</thead>
<tbody>
<tr>
<td>VAR (%)</td>
<td class="text-warning"> <i class="student-week-diff">-10.65%</i></td>
</tr>
<tr>
<td>VAR (diff)</td>
<td class="text-warning"> <i class="student-week-diff">-13,953</i></td>
</tr>
<tr>
<td>VAR (%)</td>
<td class="text-navy"> <i class="student-week-diff">8.81%</i></td>
</tr>
<tr>
<td>VAR (diff)</td>
<td class="text-navy"> <i class="student-week-diff">11,320</i></td>
</tr>
</tbody>
</table>
这是我的踪迹
var test = $(parseFloat('.student-week-diff').text());
$.each (test, function(){
if (test < 0) {
$('.student-week-diff').removeClass(".student-week-diff").addClass(".fa-level-down");
} else {
$('.student-week-diff').removeClass('.student-week-diff').addClass(".fa-level-up");
}
});