未捕获的TypeError:在检查工具中

时间:2017-11-20 15:59:06

标签: javascript

</head>
<body id-"idbd">
<p id="helloworld">Message will display here</p>
<script type="text/javascript">
Document.getElementById("idbd").style.backgroundcolor="red";
</script>
</body

当我在浏览器中打开它时,这是我的代码,背景颜色仍为白色,显示此错误。

(未捕获的TypeError:Document.getElementById不是document.html上的函数:10) 帮助我在我的代码中为红色背景改变什么????

1 个答案:

答案 0 :(得分:1)

要改变的一些事情:

<强> 1 my layout对象需要较低的内容。

变化:

<script type="text/javascript">
Document.getElementById("idbd").style.backgroundcolor="red";
</script>

要:

<script type="text/javascript">
document.getElementById("idbd").style.backgroundcolor="red";
</script>

2。 =用于分配属性,而不是-

变化:

id-"idbd"

为:

id="idbd"

3。backgroundcolor更改为backgroundColorc需要大写。

<强> 4 您还需要确保关闭所有代码,例如head代码。

将所有内容放在一起,您可以看到背景变为红色: document

最终代码:

<html>
<head>
</head>
<body id="idbd">
<p id="helloworld">Message will display here</p>
<script type="text/javascript">
document.getElementById("idbd").style.backgroundColor="red";
</script>
</body>
</html>
相关问题