2017-02-09 3 views
-2

私は都市に関する情報の表を持っています。私は、温度が32未満で標高が1000より大きい場合に画像を表示しようとしています。JQueryの2つの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(); 
    } 
});