$.ajax({
url:'https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-091?Authorization=CWB-373C6328-6BF2-41B3-BB3B-147802B82875&format=JSON&locationName=&elementName=&sort=time',
method: "GET",
datatype:"json",
success: function(res){
data = res.records.locations[0];
// console.log(data);
city = data.location;
// console.log(city);
todayWeather(data, cityNum);
selectCity(city);
weekWeather(data, cityNum);
}
})
function todayWeather(data, cityNum){
// console.log(123)
$('#weatherNow').html('');
chooseCity = data.location[cityNum].locationName
// console.log(chooseCity);
todayDate = new Date().toString().split("GMT")[0];
let weather = data.location[cityNum].weatherElement;
weatherDescription = weather[6].time[0].elementValue[0].value;
let weatherTemp = data.location[cityNum].weatherElement[1].time[0].elementValue[0].value;
let weatherImg = changeImg(weatherDescription);
$('.weather_now').html(`
${chooseCity}
${todayDate}
${weatherImg}
${weatherDescription}
溫度: ${weatherTemp} °C
`)
}