if语句(jQuery)
问题描述:
我无法弄清楚是什么导致10
一直显示为红色。其他数字的显示方式应该如此,但只有在编号10
时,如果语句未能比较正确的值。if语句(jQuery)
$(document).ready(function() {
$("thead tr td:nth-child(3)").each(function(){
var compare = $(this).text()
if(compare == 'null') {
$(this).text('No rating found').parent('tr').addClass("table-danger");
}
else if (compare <= '5') { //Number 10 keeps comparing whit this statement
$(this).parent('tr').addClass("table-danger");
}
else if (compare > '5' && compare < '7') {
$(this).parent('tr').addClass("table-info");
}
else if (compare >= '7') {
$(this).parent('tr').addClass("table-success");
}
});
});
有什么不对惠白第一else if
声明。和数量10
应该是绿色的("table-success")
答
的问题是,你与5.尝试的字符串值进行比较10多项]:
else if (parseInt(compare)<= 5)
问题已解决,但其他号码如何显示正常? – Slasher
'10'以'1'开始,因此 inarilo