未捕获的类型错误:planet.innerText 不是函数
.addEventListener("click",function() {
let planet= document.getElementById("redplanet")
planet.innerText("Nothing to report");
planet.classList.remove("alert");
})
document.getElementById("greenplanet").classList.add("alert")
html 代码:```
So my js code isn't working in inspect it says that line 23 is not a function any solution to solve this?
答案 0 :(得分:2)
错误信息非常清楚。 DOMElement.innerText
不是函数。您应该将其用作属性:
const planet = document.getElementById('redplanet');
planet.innerText = 'Hello world';
可以在此处找到现场示例:
https://jsfiddle.net/ga1ytz0j/
欲了解更多信息,请访问:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
答案 1 :(得分:1)
这不是一个函数。这是一个财产。
使用
planet.innerText = "Nothing to report";