这个文件,是说
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";
}
});
答案 0 :(得分:1)
什么是“温度度”?如果是id,则必须执行“#temperature-degree”。如果是课程,则必须执行“ .temperature-degree”。如果它是标签,则您没有任何符号,但是“温度度”不应该是标签。如果您仍然感到困惑,请查看相关文档:developer.mozilla.org/docs/Web/API/Document/querySelector