jQuery在单击时未实现请求的CSS更改

时间:2019-02-12 19:14:08

标签: javascript jquery html css

功能如下:

function background() {
                Object.keys(newImages).map((key) => newImages[key] = 'url(' + '"' + newImages[key] + '"' + ')');
                switch (city.file.icon) {
                    case "11d":
                        $("body").css('background-image', newImages.rain);
                        document.body.style.color = white;
                        break;
                    case "09d":
                        $("body").css('background-image', newImages.rain);
                        break;
                    case "10d":
                        $("body").css('background-image', newImages.rain);
                        break;
                    case "13d":
                        $("body").css('background-image', newImages.rain);
                        break;
                    case "50d":
                        $("body").css('background-image', newImages.rain);
                        break;
                }
            }

...并且问题在于,在函数调用中没有发生更改主体背景的请求。有想法吗?

编辑:

function weatherData() {
                xhr = new XMLHttpRequest();
                let data = {
                    city: 'q=' + fixInput('city')
                };
                xhr.open('POST', weather.queryImperialGetString() + data.city), true);

                xhr.onload = () => {
                    if (this.status === 200) {
                        let obj = JSON.parse(xhr.responseText);
                        let file = new weather.jsonFileConstructor(obj);
                        city.file = file;
                        document.getElementById('div_1').innerHTML = weather.showIcon(city.file.weatherIcon);
                        document.getElementById('div_2').innerHTML = "Current Temp: " + city.file.currentTemp;
                        document.getElementById('div_3').innerHTML = "High: " + city.file.hiTemp;
                        document.getElementById('div_4').innerHTML = "Low: " + city.file.loTemp;
                        document.getElementById('div_5').innerHTML = "Humidity: " + city.file.humidity;
                        document.getElementById('div_6').innerHTML = "Weather Type: " + city.file.weatherType;
                        document.getElementById('div_7').innerHTML = "Weather Description: " + city.file.weatherDescription;
                        document.getElementById('div_8').innerHTML = "Windspeed: " + city.file.windSpeed;
                        document.getElementById('div_9').innerHTML = "Wind Direction: " + city.file.windDegree;
                        document.getElementById('div_10').innerHTML = "Pressure: " + city.file.pressure;
                        background();
                    };
                };
                xhr.send();
            };

...我只是在这里说这些,因为StackOverflow不接受更多的文字就不会接受编辑...

0 个答案:

没有答案