我想要做的是,如果一个跨度的值高于它记录的某个值,如果它在控制台中更高或更低,我想用3个值做这个但是它只让我做顶二。下面是我的代码。
$(window).load(function () {
var raitingTotal = $(".total-score span").text();
if (raitingTotal >= 7) {
console.log('higher than 7');
}
if (raitingTotal <= 6.9) {
console.log('lower than 7');
}
if (raitingTotal >= 3.5) {
console.log('higher than or equal to 3.5');
}
});
答案 0 :(得分:1)
您需要使用parseFloat才能将字符串转换为数字。
$(window).load(function () {
var raitingTotal = parseFloat($(".total-score span").text());
if (raitingTotal >= 7) {
console.log('higher than 7');
}
if (raitingTotal <= 6.9) {
console.log('lower than 7');
}
if (raitingTotal >= 3.5) {
console.log('higher than or equal to 3.5');
}
});