【发布时间】:2018-02-24 03:12:32
【问题描述】:
我正在尝试设计一个 JavaScript 程序来更改 HTML 段落的文本颜色。 document.getElementById"id1".style.color = "blue";
在我拥有的 HTML 中:<p id="id1">Test</p>
每当我运行代码时,我都会收到错误消息:Uncaught TypeError: Cannot read property 'style' of null at style
我知道还有其他关于这个问题的文章,但没有一篇文章解决了我的问题。
【问题讨论】:
-
document.getElementById是一个function,需要传递一个id参数。 Javascript 中的参数传递给括号内的函数()。
标签: javascript html dom