gpt4 book ai didi

javascript - 未捕获( promise )TypeError : Cannot set property 'textContent' of null

转载 作者:行者123 更新时间:2023-11-30 19:33:00 25 4
gpt4 key购买 nike

the javascript file picture

这个文件,上面写着

Uncaught (in promise) TypeError: Cannot set property 'textContent' of null
at app.js:25
window.addEventListener('load', () => {
let long;
let lat;
let temperatureTimeZone = document.querySelector("temperature-timezone");
let temperatureDegree = document.querySelector("temperature-degree");
let temperatureDescription = document.querySelector("temperature-description");

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude;
lat = position.coords.longitude;

const proxy = `https://cors-anywhere.herokuapp.com/`;
const api = `${proxy}https://api.darksky.net/forecast/1299787a9e937056e2ee6cb21ebfc2d4/${lat},${long}`;

fetch(api)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
const { temperature, summary, precipType, icon } = data.currently;

// set Dom Elements from APi
temperatureDegree.textContent = temperature;
});
});
} else {
h1.textcontent = "Hey reload site and allow geolocation";
}
});

最佳答案

什么是“温度”?如果它是一个 id,那么你必须做“#temperature-degree”。如果它是一个类,那么你必须做“.temperature-degree”。如果它是一个标签,那么你没有任何符号,但“温度-度数”不应该是一个标签。如果您仍然感到困惑,请查看它的文档:developer.mozilla.org/docs/Web/API/Document/querySelector

关于javascript - 未捕获( promise )TypeError : Cannot set property 'textContent' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56241224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com