getElementByClassName()-不是函数 [英] getElementByClassName() - is not a function

查看:154
本文介绍了getElementByClassName()-不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望下面的代码将Random1和Random2更改为Random,但是它什么也没做。当我在chrome中检查开发人员工具时,它显示 document.getElementByClassName不是函数。

I expected the code below to change Random1 and Random2 to Random but its not doing anything. When I checked developers tool in chrome, it showed "document.getElementByClassName is not a function". Any help will be appreciated.

我的HTML:

<h3 class="Rand"><i>Random1 </i></h3>
<h3 class="Rand">Random2</h3>

我的JavaScript:

My JavaScript:

var elems = document.getElementByClassName('Rand');     
for(var i = 0; i <= elems.length; i++)
{
elems[i].innerHTML = "Random";
}


推荐答案

您应使用 getElementsByClassName 代替使用getElementByClassName。看来您拼写错误。

You should use getElementsByClassName instead using getElementByClassName. It seems you misspelled.

这篇关于getElementByClassName()-不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆