Javascript TypeError:无法设置属性';文本内容';无效;temperatureDegree.textContent=温度
我正在制作一个天气应用程序,无法编辑“textContent”而不会出现错误:temperatureDegree.textContent=temperatureJavascript TypeError:无法设置属性';文本内容';无效;temperatureDegree.textContent=温度,javascript,Javascript,我正在制作一个天气应用程序,无法编辑“textContent”而不会出现错误:temperatureDegree.textContent=temperature window.addEventListener("load", ()=> { let long let lat let temperatureDescription = document.querySelector("temperature-description") let temperature
window.addEventListener("load", ()=> {
let long
let lat
let temperatureDescription = document.querySelector("temperature-description")
let temperatureDegree = document.querySelector("temperature-degree")
let locationTimezone = document.querySelector("location-timezone")
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude
lat = position.coords.latitude
const proxy = "http://cors-anywhere.herokuapp.com/"
const api = `${proxy}https://api.darksky.net/forecast/503a88031807535a11c0654c147002d5/${lat},${long}`
fetch(api)
.then(response => {
return response.json()
})
.then(data => {
console.log(data)
const {temperature, summary} = data.currently
//Set DOM Elements from the API
temperatureDegree.textContent = temperature
})
})
} else {
h1.textContent = "We can't find your location...make sure it is activated."
}
})
必须在选择器符号之前。如果温度等级是一个id,则在其前面加上散列(
#
)符号
或者,如果它是一个类,则在它前面加上点(
)符号
您还必须对其他元素执行相同的操作。您必须在选择器符号之前。如果温度等级是一个id,则在其前面加上散列(
#
)符号
或者,如果它是一个类,则在它前面加上点(
)符号
您还必须对其他元素执行相同的操作。如果您使用
类
来选择DOM
元素,请使用
let temperatureDegree = document.querySelector(".temperature-degree");
如果您使用id
,请使用
let temperatureDegree = document.querySelector("#temperature-degree");
如果使用
Class
选择DOM
元素,请使用
let temperatureDegree = document.querySelector(".temperature-degree");
如果您使用id
,请使用
let temperatureDegree = document.querySelector("#temperature-degree");
向我们展示您的
HTML
代码。向我们展示您的HTML
代码。