2017-02-09 147 views
-2

我有一张关于城市的信息表。我试图在温度低于32并且海拔高于1000时显示图像(在div内)。JQuery两个if语句

我的声明不断出现错误。

$("td.condition").each(function(){ 
    if($("td.elevation").text() > 1000) && ($("td.high_temp").text() < 32)));  
    } 
    $(".ice").show(); 
}); 
+0

阅读错误将是一个很好的第一步。这看起来像是一个奇怪的混合语法错误。你有一个空的'if'块,然后关闭该函数,然后在关闭该函数后尝试使用更多代码,然后尝试再次关闭该函数*。 – David

回答

1

这是一个很破的结构:

$("td.condition").each(function(){ 
    if($("td.elevation").text() > 1000) && ($("td.high_temp").text() < 32))); 
    // The above is an empty "if" because of the semi-colon after it. 
    // So it checks the condition, but then doesn't do anything. 
} 
// Now the anonymous function is closed. 
$(".ice").show(); 
// Which means the above line of code is trying to be passed as an argument to each(), which doesn't make sense. 
}); 
// Then you have a stray } and then close the call to each() 

如果以.show()该呼叫被认为是if块内,那么你要放在一个大括号块以下的if

$("td.condition").each(function(){ 
    if($("td.elevation").text() > 1000) && ($("td.high_temp").text() < 32))) { 
     $(".ice").show(); 
    } 
});