为什么这个“if声明”不起作用?

时间:2016-10-03 20:04:44

标签: javascript jquery if-statement range

我已经构建了一个完美运行的天气应用程序。我决定在已分配的API中添加使用weather id变量更改的图标。它适用于if语句中的第一个id,但是当我添加else时if语句中的语句不适用于else,如果这里的部分是我的代码:

{{1}}
我在这句话中遗漏了什么?

2 个答案:

答案 0 :(得分:3)

你在第一个if中错过了一个相等的符号(=)。它应该是这样的:

if(weatherId==800){
   $('#type').css('background-image', 'url(http://publicdomainvectors.org/photos/weather-clear.png)');
}
else if(weatherId>=801 && weatherId<=804){
    $('#type').css('background-image','url(http://publicdomainvectors.org/tn_img/stylized_basic_cloud.png)');
}
else if(weatherId>=300 && weatherId<=531){
     $('#type').css('background-image','url(http://publicdomainvectors.org/tn_img/sivvus_weather_symbols_4.png)');
}

答案 1 :(得分:2)

更改

if(weatherId=800){

if(weatherId==800){

注意double ==

相关问题