为什么下面这段代码1无法改变背景颜色,而代码2可以。他们的有区别吗?
代码1:
<body>
<input type="button" onclick="document.getElementByTagName("body").style.backgroundColor='lavender';"
value="改变背景色">
</body>
代码2:
<body>
<input type="button"
onclick="document.body.style.backgroundColor='lavender';"
value="改变背景色">
</body>
第一、应该是
getElementsByTagName
你少写了个 s第二,这个东西 返回的是一个
HTMLCollection
或者说是一个数组,所以应该写为