2016-10-03 66 views
-3

我建立了一個完美的天氣應用程序。我決定添加一個圖標,這些圖標會根據已分配的API的天氣ID變量進行更改。它適用於第一個ID if語句,但是當我添加否則,如果它裏面的語句不爲別的工作,如果在這裏的部分是我的代碼:爲什麼不是這個「如果陳述」工作?

 //weather icons check  
      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)'); 
      } 

我失去了這個說法東西? ?

+3

'Weatherid = 800'是一項任務。將其更改爲'if(weatherId == 800){' –

+0

'weatherId = 800' – epascarello

+1

'weatherid === 800' triple equal is best。 –

回答

3

你已經錯過了你的第一個如果等號(=)。它應該是這樣的:

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)'); 
} 
+0

我剛剛意識到這一點。非常感謝你 – MikeL5799

+0

@ MikeL5799你可以接受答案,如果這解決了你的問題:) –

2

變化

if(weatherId=800){ 

if(weatherId==800){ 

注意雙==

+0

我剛剛注意到它,非常感謝你 – MikeL5799